Create a NSSet from NSArray based on property

前端 未结 5 1755
礼貌的吻别
礼貌的吻别 2021-01-12 04:22

How does one create a NSSet of objects from an array based on a property.

e.g. Array of objects, each with a strong reference to a type pro

5条回答
  •  悲&欢浪女
    2021-01-12 04:54

    NSMutableSet* classes = [[NSMutableSet alloc] init];
    NSMutableSet* actualSet = [[NSMutableSet alloc] init];
    
    for(id object in array) {
        if([classes containsObject:[object class]] == NO) {
            [classes addObject:[object class]];
            [actualSet addObject:object];
        }        
    }
    

提交回复
热议问题