0

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

1 Answer 1

1

You can use valueForKey: to create an array that contains your ids and then use that to create an NSSet

NSSet<NSString *> *idSet = [NSSet setWithArray:[arrayOfSomethings valueForKey:@"id"]];
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.