Reputation: 20410
I don't know if there is an easy way to implement this, or I need to implemente the algorithm by myself.
This is what I have (NSDictionary):
{
14 = (
"M"
);
15 = (
"H"
);
16 = (
"F",
"G"
);
And this is what I want (NSArray):
{
14,
"M",
15,
"H"
...
}
Im looking for an easy way, in case I need to do the algorithm I'll do by myself
Upvotes: 1
Views: 2255
Reputation: 7344
You could iterate over the NSDictionary
and add the keys and values like this:
NSMutableArray *array = [NSMutableArray array];
[may enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop)
{
[array addObject:key];
for (int i = 0; i < [obj count]; i++){
[array addObject:[obj objectAtIndex:i]];
}
}];
Upvotes: 3
Reputation: 29767
Try this way:
NSMutableArray *allObjs = [[NSMutableArray alloc] initWithArray:[d allKeys ]];
[allObjs addObjectsFromArray:[d allValues]];
Upvotes: 1