• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: odd problem with NSMutableDictionary and initWithContentsOfFile
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: odd problem with NSMutableDictionary and initWithContentsOfFile


  • Subject: Re: odd problem with NSMutableDictionary and initWithContentsOfFile
  • From: Jason Coco <email@hidden>
  • Date: Thu, 29 May 2008 11:44:56 -0400


On May 29, 2008, at 10:47 , Jens Alfke wrote:


On 29 May '08, at 6:41 AM, Leslie Smith wrote:

I found out what I was doing wrong:  rather than

[SimParamnames initWithContentsOfFile: aFile];

I should have had

SimParamnames = [SimParamnames initWithContentsOfFile: aFile];

No. As two people have said already, *you can't initialize an object more than once*. The only time an init method is to be called is right after -alloc, when the object is first created. Calling it again will unexpectedly reset part of the object's state, and probably mess it up.


What you should do instead of the above line is
[SimParamnames release]; // to get rid of the old object
SimParamnames = [[NSDictionary alloc] initWithContentsOfFile: aFile]; // new object

If for some reason you absolutely want/need to use the NSMutableDictionary that you originally allocated, you can do something like this:


[SimParamnames removeAllObjects];
[SimParamnames addEntriesFromDictionary:[NSDictionary dictionaryWithContentsOfFile:aFile]];


That should work as expected without releasing the original mutable dictionary (assuming you really do need it for something you cut in the example).
_______________________________________________


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


References: 
 >re: odd problem with NSMutableDictionary and initWithContentsOfFile (From: Leslie Smith <email@hidden>)
 >Re: odd problem with NSMutableDictionary and initWithContentsOfFile (From: Jens Alfke <email@hidden>)

  • Prev by Date: RE: Appending to file with writeToFile
  • Next by Date: Re: 10.5.3 Release Notes?
  • Previous by thread: Re: odd problem with NSMutableDictionary and initWithContentsOfFile
  • Next by thread: "Enter" key down
  • Index(es):
    • Date
    • Thread