Re: [Newbie] Good NSDictionary example?
Re: [Newbie] Good NSDictionary example?
- Subject: Re: [Newbie] Good NSDictionary example?
- From: Andreas Mayer <email@hidden>
- Date: Sun, 8 Sep 2002 14:08:38 +0200
Am Sonntag, 08.09.02 um 06:11 Uhr schrieb Keith Pritchard:
id myDict=[NSMutableDictionary dictionaryWithObjectsAndKeys:
Unless there's a good reason not to, use a qualified type:
NSMutableDictionary *myDict = [...
That will help the compiler to detect errors in your code.
I tried [myDict retain] but ok, I suppose that was a bit optimistic :-)
That's fine.
But it seems, your myDict variable got out of scope.
So the object is still there, but you have no way to access ist.
How can I make it accessible to the whole controller?
You will have to declare it as a property of the controller class.
Next you'll probably want to write setter and getter methods:
- (void)setMyDict:(NSMutableDictionary *)newMyDict
{
NSMutableDictionary *oldValue = myDict;
myDict = [newMyDict retain];
[oldValue release];
}
- (NSMutableDictionary *)myDict
{
return myDict;
}
Put these methods in your public interface to access myDict from
outside your controller.
And don't forget to release it when the controller is destroyed:
- (void)dealloc
{
[myDict release];
... more ...
[super dealloc];
}
bye. Andreas.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.