Re: odd problem with NSMutableDictionary and initWithContentsOfFile
Re: odd problem with NSMutableDictionary and initWithContentsOfFile
- Subject: Re: odd problem with NSMutableDictionary and initWithContentsOfFile
- From: Michael Vannorsdel <email@hidden>
- Date: Thu, 29 May 2008 02:46:39 -0600
You can't init an object more than once (well not an intended use).
You do:
SimParamnames = [NSMutableDictionary dictionary];
and later:
[SimParamnames initWithContentsOfFile: aFile];
which are both initializing the object. The second init is either
being ignored or perhaps corrupting the object. If you want a mutable
dictionary of a file's contents you'll have to make a new one with
[NSMutableDictionary dictionaryWithContentsOfFile:filePath].
[SimParamnames removeAllObjects] ;
[SimParamnames initWithContentsOfFile: aFile];
might work better as:
[SimParamnames release]; //throw away the old dictionary
SimParamnames = [[NSMutableDictionary alloc]
initWithContentsOfFile:aFile]; //make a new one from aFile
On May 28, 2008, at 1:58 AM, Leslie Smith wrote:
in a later method
NSArray *filesToOpen = [oPanel filenames];
int i, count1 = [filesToOpen count];
for (i=0; i<count1; i++) {
NSString *aFile = [filesToOpen objectAtIndex:i];
printf("%s\n", [aFile UTF8String]) ;
[SimParamnames removeAllObjects] ;
[SimParamnames initWithContentsOfFile: aFile];
NSLog(@"SimParamnames contains %d values", [SimParamnames count]) ;
xxx = [NSMutableDictionary dictionaryWithContentsOfFile: aFile];
NSLog(@"SimParamnames contains %d values", [SimParamnames count]) ;
NSLog(@"xxx contains %d values", [xxx count]) ;
result = 100 ;
}
_______________________________________________
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