tags:

views:

29

answers:

2

I have use below syntax for for set the object.

[dict setObject:eventArray forKey:categoryName];

Now i am trying to get below syntax but i got nothing.

NSMutableArray *tempArrayValue=[[NSMutableArray alloc]init];
tempArrayValue =[tempDict valueForKey:categoryValue];

What is the problem i cant understand can u help me?

A: 

you have given key as categoryName not categoryValue, and while retrieving you are using categoryValue.

NSMutableArray *tempArrayValue=[[NSMutableArray alloc]init]; tempArrayValue =[tempDict valueForKey:categoryName];
Ruchir Shah
in CategoryName and Categoryvalue contain same data
MD
are dict and tempDict have the same value?
Ruchir Shah
A: 

If you're setting the value like this:

[dict setObject:eventArray forKey:categoryName];

Then you should be fetching it back again like this:

NSMutableArray* eventArray = [dict valueForKey:categoryName];

assuming that eventArray is of type NSMutableArray.

What you are doing has at least two different problems.

This line is a memory leak, since you allocate an object and then throw it away, so delete it:

NSMutableArray *tempArrayValue=[[NSMutableArray alloc]init];

This second line may return a nil object, if there is no object stored for the key categoryValue. (You are using an object called categoryName above, as the key to store the value):

tempArrayValue =[tempDict valueForKey:categoryValue];

You haven't posted enough code to be able to tell why it's not working otherwise.

Shaggy Frog