nsset1: person.ID = 1,person.ID = 2,person.ID = 3nsset2: person.ID = 1,person.ID = 2
结果应该是:
nsset1 - nsset2: person (with ID 3)nsset2 - nsset1: null
这两个集中具有相同ID的对象是不同的对象,所以我不能简单地做minusSet.
我想做的事情如下:
nsset1: person.ID = 1,person.ID = 3nsset2: person.ID = 4,person.ID = 5
结果应该是这样的:
nsset1 - nsset2: person (ID 1),person (ID 2),person (ID 3)nsset2 - nsset1: person (ID 4),person (ID 5)
做这个的最好方式是什么?
解决方法 你应该尝试这样的事情NSSet* nsset1 = [NSSet setWithObjects:person_with_ID_1,person_with_ID_2,person_with_ID_3,nil];NSSet* nsset2 = [NSSet setWithObjects:person_with_ID_2,person_with_ID_4,nil];// retrIEve the IDs of the objects in nsset2NSSet* nsset2_IDs = [nsset2 valueForKey:@"objectID"]; // only keep the objects of nsset1 whose 'ID' are not in nsset2_IDsNSSet* nsset1_minus_nsset2 = [nsset1 filteredSetUsingPredicate: [nspredicate predicateWithFormat:@"NOT objectID IN %@",nsset2_IDs]];总结
以上是内存溢出为你收集整理的iphone – 如何根据对象的属性比较两个NSSets?全部内容,希望文章能够帮你解决iphone – 如何根据对象的属性比较两个NSSets?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)