Hi,
I've encountered a little problem while doing some beginner programming in Objective-C. The problem is that I apparently don't understand how to use init. What I'm kind of (it is a little bigger, actually) trying to do is the following:
I want to have an ivar which holds the name of an object, declared as "NSString* name;" in the @interface section and then have it initialized with a string in the init method in my @implentation. The string basically has to be something like "No name given yet.". But when I call my init method in main, my string keeps being null/nil.
From my understanding, the problem lies in the following line of code:
AnIrrelevantClass* myObject = [myObject init];
With the problem being that the init method never gets called. (I included a NSLog call in my init method to check)
I suspect this has something to do with some new memory management techniques and with the fact that you normally chain an init with the alloc method, which doesn't work. Can someone please help me with this?
Thanks.
Also I apologize if some parts of my post are a bit vague/strange, but I'm quite tired right now.
I've encountered a little problem while doing some beginner programming in Objective-C. The problem is that I apparently don't understand how to use init. What I'm kind of (it is a little bigger, actually) trying to do is the following:
I want to have an ivar which holds the name of an object, declared as "NSString* name;" in the @interface section and then have it initialized with a string in the init method in my @implentation. The string basically has to be something like "No name given yet.". But when I call my init method in main, my string keeps being null/nil.
From my understanding, the problem lies in the following line of code:
AnIrrelevantClass* myObject = [myObject init];
With the problem being that the init method never gets called. (I included a NSLog call in my init method to check)
I suspect this has something to do with some new memory management techniques and with the fact that you normally chain an init with the alloc method, which doesn't work. Can someone please help me with this?
Thanks.
Also I apologize if some parts of my post are a bit vague/strange, but I'm quite tired right now.