2

I have NSMutable dictionary like this

[dict setObject:arrItems forKey:@"Added"];

where "arrItems" is an array, so my dictionary contains arrays. Problem is how can I retrieve real objects from dictionary. not as array objects.

when I tried like this

[myArray addObject:[dict objectForKey:@"Added"]];

It's added objects to myArray as complete "arrItems" array. I want to add objects of arrItems to myArray.

Please give me a help

0

5 Answers 5

4

You need [myArray addObjectsFromArray:[dict objectForKey:@"Added"]]

I recommend you learn to use the documentation, as this is clearly documented in the NSArray documentation.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks a lot for your help. its ok now. :) still Im quit new to iPhone SDK, thanks for your help.
1

You need to use the addObjectsFromArray: selector like so which will append the Objects retrieved from the array stored in the Dictionary (arrItems) to the end of myArray:

[myArray addObjectsFromArray:[dict objectForKey:@"Added"]];

You can find more information on Apple's Documentation on NSMutableArray

Comments

1
[myArray addObject:[(NSArray *)[dict objectForKey:@"Added"] objectAtIndex:0]];

Comments

1

You need to loop through arrItems and add them individually which is the simplest solution.

However i think you can type cast the returned object from the dictionary into a NSArray and then create a new array with it.

NSArray *anArray = (NSArray *)[dict objectForKey:@"Added"];
NSMutableArray * myArray  = [NSMutableArray array];
[myArray addObjectsFromArray:anArray];

Comments

1

[dict objectForKey@"Added] returns an NSArray object?

So, if you want to add an object of the NSArray, you need to call something like that

[[dict objectForKey@"Added] objectAtIndex:index]

Comments

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.