Re: Objects return nil
Re: Objects return nil
- Subject: Re: Objects return nil
- From: Michael Hanna <email@hidden>
- Date: Thu, 7 Aug 2003 13:49:03 -0400
Thank you all for pointing this out..
I think the main problem is I was taught programming on Java and I had
come to depend on the Java compiler warnings. A bad habit, I know.
Michael
On Thursday, August 7, 2003, at 12:30 PM, Jonathan Jackel wrote:
- (id)init
{
self = [super init];
linesPath = [[NSBundle mainBundle] pathForResource:@"lines"
ofType:@"plist"];
lineDict = [NSDictionary dictionaryWithContentsOfFile:
linesPath];
key = @"lines"; // key to get lineArray from the
NSDictionary
tokenString = @"%s"; // the 12 tokens to be replaced within the
while-loop
tokenLines = [lineDict objectForKey:key];
NSLog(@"tokenLines: %@", tokenLines); // p/o the
contents fine
return self;
}
tokenLines becomes nil at the end of the event loop because you don't
retain
what it points to. You should have done:
tokenLines = [[lineDict objectForKey:key] retain];
You need to brush up on retain and release. Search on
cocoa.mamasam.com and
you will find a number of references to useful articles.
Why do my objects return nothing? Also, the NSArray returned is
retrieved as an NSMutableArray. Is explicit casting necessary?
You can return a mutable array even if your method says it returns an
immutable array. No casting is required. It won't work the other way
around, though.
Jonathan
_______________________________________________
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.