CosmicMind / Graph

Graph is a semantic database that is used to create data-driven applications.
http://cosmicmind.com
MIT License
873 stars 72 forks source link

Using subclasses #136

Closed CAP-ONE closed 7 years ago

CAP-ONE commented 7 years ago

I don't see and documentation about this, nor opened issue, so it must be an obvious thing for anyone but I'm still trying to wrap my head around this. I'm using the Search API, according to the sample project, but I want to store my custom object for later reuse.

I've something like :

var countriesList: [Country]!

[...]

for country in countriesList {
   let countryE = Entity(type: "Country")
   countryE["country"] = country
}

but when calling later

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { let countryE = data[indexPath.row] let country = countryE["country"] as? Country print("Selected: (country?.name)") }

I'm getting an error like [MyApp.Country initWithCoder:]: unrecognized selector sent to instance I tried to subclass Entity but apparently i'm not allowed to do it (Cannot inherit from non-open class 'Entity' outside of its defining module) So I googled (a lot) and saw that I need to inherit from NSObject and implement NSCoding protocol in my custom object but after that, all my object property are returning nil. Is there a way, or does Graph provide a way to use custom object to work with the library ? Thanks

daniel-jonathan commented 7 years ago

Graph can store a custom object as a property if that object adheres to the CoreData TransformableAttributeType. Give that a try, if it doesn't work, I'd be happy to help you further on Graph Gitter. Either way, let me know how it turns out :) Thank you!

CAP-ONE commented 7 years ago

I posted on the Graph Gitter, it doesn't seems so active compared to Material, since the last message posted is from last March, so just to let you know

daniel-jonathan commented 7 years ago

I saw there is a post, and usually I answer within 24 hours. I'll respond later today:)