开发者

how to get NSmutable array from the NSMutableDictionary?

开发者 https://www.devze.com 2022-12-19 09:33 出处:网络
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.

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:categoryV开发者_运维知识库alue];

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


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

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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消