NSManagedObject relationship NSSet iteration
I have a subclassed NSManagedObject
(ObjectA) which has a relationship one-to-may to another subclassed NSManagedOb开发者_Python百科ject
(ObjectB). I get the ObjectB NSSet
from ObjectA's generated method.
I want to determine if an ObjectB with a given 'name' exists in the returned NSSet
(e.g. ObjectB.name == "xxx"
).
What is the most efficient way to determine the NSSet
contains the object instead of iterating/comparing my way through the whole NSSet
?
Cheers
To get a set with all objects matching the condition:
[aSet filteredSetUsingPredicate [NSPredicate predicateWithFormat:@"name like %@", aString]]
A simple count would be enough to create an expression useable in a condition.
[[aSet filteredSetUsingPredicate [NSPredicate predicateWithFormat:@"name like %@", aString]] count]
精彩评论