I have an array of somethings, I'd like to make a set from an NSString property on this object:
@protocol something<NSObject>
@property(nonatomic, readonly) NSString *Id;
@end
I have an array of somethings:
NSArray<id<something>> *arrayOfSomethings;
I'd like to get a NSSet of the Id properties:
NSSet<NSString *> *idSet = ?; // Calculate from arrayOfSomethings.
How do I do this? Thanks
You can use valueForKey:
to create an array that contains your id
s and then use that to create an NSSet
NSSet<NSString *> *idSet = [NSSet setWithArray:[arrayOfSomethings valueForKey:@"id"]];