0

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?

0

1 Answer 1

3

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"];
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for your reply.. But how can I get the individual object from the array & key of that object. I want to display the title & id in the TableView cell.
@user2526811: Take a look at Update section in my Answer.

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.