开发者

NSManagedObject relationship NSSet iteration

开发者 https://www.devze.com 2022-12-08 03:35 出处:网络
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 me

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]

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号