Re: What happens after adding an object to a NSMutableDictionary
Re: What happens after adding an object to a NSMutableDictionary
- Subject: Re: What happens after adding an object to a NSMutableDictionary
- From: Keary Suska <email@hidden>
- Date: Mon, 3 May 2010 14:56:55 -0600
On May 3, 2010, at 2:39 PM, Dominic Dauer wrote:
> Hello,
> I want to add an Object to a NSMutableDictionary:
>
> if(!parsedClasses)
> parsedClasses = [[NSMutableDictionary alloc] initWithObjectsAndKeys:oneClass,[oneClass objectAtIndex:0],nil];
> else
> [parsedClasses setObject:[oneClass retain] forKey:[oneClass objectAtIndex:0]];
>
> After this I remove all objects and keys from the NSMutableArray oneClass to fill it again with other objects.
>
> [oneClass removeAllObjects];
>
> When I try to access the the objects of parsedClass I see that every object is nil.
This is not possible, or your description is inaccurate. Dictionaries cannot contain nil values, but -objectForKey: will return nil if the key doesn't exist.
Anyway, are you sure that "oneClass" is non-nil in you code? Have you stepped through the code using the debugger to see if the values are what you expect, and are being added to the dictionary properly?
> What happens after I adding an oneClass MutableArray Object to the parsedClasses MutableDictionary and how can I preserve the oneClass objects in parsedClasses after removing all objects?
NSDictionary copies keys and retains objects, so you should never "lose" them if an owning collection releases them. Also, objects are not automatically removed from a collection when their reference becomes invalid (completely released). Chances are, they are not getting added to the dictionary at all. Chances are, "oneClass" is nil.
HTH,
Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden