Compare NSSets for a Single Property

I am trying to determine if two NSS types are "equal", but not in the sense of isEqualToSet. Elements in two sets are the same class, but are not the same object, or even references to the same object. They will have one property, which will be the same, let him call his "name".

I believe that it is better to compare these two sets to perform a simple test of a test suite and then more complex PassingTest objects: for each element in one set, make sure that the element with the same name is in another set? I hope that for this case there is something simpler.

+3
source share
3 answers

valueForKey: .

if ([[set1 valueForKey:@"name"] isEqualToSet:[set2 valueForKey:@"name"]]) {
    // the sets match your criteria
}
+2

, ( )..

, , NSDictionary , :

- (NSDictionary *)itemProperties
{
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
    [dict setObject:self.name forKey:@"name"];
    [dict setObject:self.id forKey:@"id"];
    return dict;
}

valueForKey:, :

BOOL userSetsEqual = [[userSet1 valueForKey:@"itemProperties"]
    isEqualToSet:[userSet2 valueForKey:@"itemProperties"]];

... userSet1 userSet2 NSS, .

+3

, , . - , . -sortedArrayUsingDescriptors:, , . , -filteredSetUsingPredicate: count.

, , , , . , , , . .

0

Source: https://habr.com/ru/post/1773450/


All Articles