cdub
cdub

Reputation: 25751

Easiest way to turn NSMutableDictionary into an NSArray

I have an NSMutableDictionary that is finished loading it's data. The dictionary has data like so:

NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];

The data is just NSStrings. So like this would be an example:

dict[@"a"] = @"a";
dict[@"b"] = @"b";
dict[@"c"] = @"c";

I don't know what the data will be till the loop that generates it is run (but it will be like the pattern above).

What's the best/easiest way to turn this into an NSArray?

Upvotes: 0

Views: 58

Answers (1)

Shamas S
Shamas S

Reputation: 7549

If you want to convert it into an NSArray only keeping its keys, you should use

NSArray *keysArray =  [dict allKeys];

If you want values, you can use

NSArray *valuesArray = [dict allValues];

If you want both, you can add them.

Upvotes: 2

Related Questions