I have a Entity with a column of type ID named “responsibleUsers”. In this column I store an Array containing NSNumbers.
I want to fetch all objects of this entity, that match my current User. Therefore i create following predicate:
[NSPredicate predicateWithFormat: @"%@ IN responsibleUsers",[NSNumber numberWithInteger: curUser.oID.integerValue] ]
whatever I try, my App crashes. Once with a EXC_BAD_ACESS, once with “unimplemented SQL generation for predicate nsnumber”
What is the correct way to query my entity?
The query you are trying assumes that you have two entities: the entity you querying (let’s call it
Group) and another one, perhaps calledUser, which is set up as a to-many relationship fromGroupcalledresponsibleUsers. You would then be able to use the predicate you suggest:This would be the recommended use of Core Data object graphs.
In your setup, it seems you have an array of
NSNumberset as a property rather than a relationship. Therefore you cannot use such a query. You simply have to retrieve the array and query the array.If you are indeed querying something like a group of users, I would recommend the first approach. If you are querying some kind of user, I would suggest a
BOOLpropertyresponsibleas the most efficient solution.