Reputation: 58
Which type I should use to save many objects with same key?
I should post data to server where one of parameter is suggestedTo and it contains userId. This parameters should be more then one. So I'm confused which data type I should use to save them. For example array or dictionary should looks like
{
@"suggestedTo" = 111,
@"suggestedTo" = 222,
@"suggestedTo" = 333,
etc.
}
Upvotes: 0
Views: 505
Reputation: 299355
This is typically handled with a dictionary of sets (or arrays if the data is ordered). So in this case, you'd have something like:
NSSet *suggestedTo = [NSSet setWithObjects:[NSNumber numberWithInt:111],
[NSNumber numberWithInt:222],
[NSNumber numberWithInt:333], nil];
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:suggestedTo,
@"suggestedTo", nil];
Upvotes: 3
Reputation: 38728
You could use a dictionary of arrays
NSArray *suggestedTos = [[NSArray alloc] initWithObjects:
[NSNumber numberWithInt:111],
[NSNumber numberWithInt:222],
[NSNumber numberWithInt:333], nil];
NSDictionary *myDictionary = [[NSDictionary alloc] initWithObjectsAndKeys:
suggestedTos, @"suggestedTo", nil];
Upvotes: 2