我有两个nssets.
nsset1: person.id = 1,person.id = 2,person.id = 3 nsset2: person.id = 1,person.id = 2
结果应该是:
nsset1 - nsset2: person (with id 3) nsset2 - nsset1: null
这两个集中具有相同id的对象是不同的对象,所以我不能简单地做minusSet.
我想做的事情如下:
nsset1: person.id = 1,person.id = 3 nsset2: 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 nsset2 NSSet* nsset2_ids = [nsset2 valueForKey:@"objectID"]; // only keep the objects of nsset1 whose 'id' are not in nsset2_ids NSSet* nsset1_minus_nsset2 = [nsset1 filteredSetUsingPredicate: [NSPredicate predicateWithFormat:@"NOT objectID IN %@",nsset2_ids]];
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。