Reputation: 1253
I have 2 array like as follow:
Array A (
{ title="A",id=1 }, {title="B",id=2},{title="c",id=3}
)
Array B (
{ title="A",id=1 }, {title="B",id=2},{title="c",id=3}
)
Now, I want to combine this arrays
& when I try to get the values from combined array, I want know that it is from Array A or Array B.
How can I do that?
Should I use dictionary instead of Array?
Upvotes: 0
Views: 404
Reputation: 27225
Yes, you should use Dictionary
instead of Array
. Set the Array as an Object with the Key as ArrayName.
Sample Code :
NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:arrayA,@"ArrayA",arrayB,@"ArrayB", nil];
NSLog(@"dict :: %@",dict);
Update :
To display the title & id in the TableView
cell :
yourTitleLabel.text = [[[dict objectForKey:@"ArrayA"] objectAtIndex:indexPath.row] objectForKey:@"title"];
yourIdLabel.text = [[[dict objectForKey:@"ArrayA"] objectAtIndex:indexPath.row] objectForKey:@"id"];
Upvotes: 3