FROM : Jens Alfke
DATE : Thu May 29 16:47:38 2008
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
—Jens
DATE : Thu May 29 16:47:38 2008
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
—Jens
| Related mails | Author | Date |
|---|---|---|
| Leslie Smith | May 28, 09:58 | |
| Ken Ferry | May 29, 10:39 | |
| Michael Vannorsdel | May 29, 10:46 | |
| Leslie Smith | May 29, 15:41 | |
| Jason Stephenson | May 29, 15:50 | |
| Andy Lee | May 29, 16:44 | |
| Jens Alfke | May 29, 16:47 | |
| Jason Coco | May 29, 17:44 |






Cocoa mail archive

