使用自定义类属性的两个NSMutableSets的平等 [英] Equality of Two NSMutableSets Using Custom Class Attributes
问题描述
如何检查两个 NSMutableSets
是否相等(相同成员,成员数量)
我的实现 isEqualToSet
似乎无效。
// members is a NSMutableSet of AUser objects
// users is also a NSMutableSet of AUser objects, it is an attribute of instances of the AGroup class
[[group valueForKey:@"users"] isEqualToSet:members]
AGroup
- users
AUser
- name (String)
如何检查集合是否相等名称属性?
How do I check if the sets are equal by checking their name attributes?
对不起,由于我缺乏知识,这是我第一次使用iOS编程,所以我只知道当前的基本知识。
Sorry for my lack of knowledge, it's my first time with iOS programming, so I only know the basics at the moment.
推荐答案
如果你想检查相应的 name
属性是否相同, / p>
If you want to check if the corresponding name
attributes are identical, the following should work:
[[group valueForKeyPath:@"users.name"] isEqualToSet:[members valueForKey:@"name"]]
[group valueForKeyPath:@users.name]
返回组中所有用户的名称集, [members valueForKey:@name]
返回<$ c中所有用户的名称集$ c>会员。
[group valueForKeyPath:@"users.name"]
returns the set of the names of all users in the group, and [members valueForKey:@"name"]
returns the set of the names of all users in the members
set.
更新: > members 是一组字符串,而不是一组用户对象。因此代码简化为:
Update: As it became clear in the comments, members
is a set of strings, and not a set of user objects. Therefore the code simplifies to:
[[group valueForKeyPath:@"users.name"] isEqualToSet:members]
这篇关于使用自定义类属性的两个NSMutableSets的平等的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!