Very new to Core Data, but I read that I can get data that uses an Entity relationship. Now, based on Mysql, maybe I'm making too many assumptions, but I have 2 objects configured with a relationship between them, and I can’t get the correct data.
Here are my 2 models:
@objc(Categories) class Categories: NSManagedObject { @NSManaged var category: String @NSManaged var exp: String @NSManaged var order: NSNumber } @objc(Techniques) class Techniques: NSManagedObject { @NSManaged var korean: String @NSManaged var order: NSNumber @NSManaged var spanish: String @NSManaged var categories: Categories }
After I created the relation of methods to categories, Core Data added this field to Sqlite DB:
ZCATEGORIES - INTEGER
Let's say I want to get all the methods related to category # 3 (with internal ZID: 3)
If I do this:
request.predicate = NSPredicate(format: "categories == %@", 3)
It works. But if I do this:
request.predicate = NSPredicate(format: "categories == %@", category.category)
This does not work. I understand that this does not work, because category.category is a string, not an integer.
My question is:
Should I create my own field of relationship identifiers in the Category object and set it, and then call the method, for example:
request.predicate = NSPredicate(format: "categories == %@", category.categoryID)
?
Is there a way to access the internal category identifier to make this relation work?
Or, even better, it seems to me that in order to get this relationship there should be an internal mechanic, not writing a SQL-like query, but simply using Object, something like: Techniques.categores .
Thanks. I have not found a good answer anywhere.