Re: Noob question regarding Cocoa objects.
Re: Noob question regarding Cocoa objects.
- Subject: Re: Noob question regarding Cocoa objects.
- From: Nir Soffer <email@hidden>
- Date: Tue, 28 Nov 2006 21:36:16 +0200
On Nov 28, 2006, at 20:49, Scott Ribe wrote:
You can also call another init method in the same class, but in the
end the appropriate super class' init method must be called first
before you start initializing your object
- (id)initWithParam:(int)param
{
if ( (self=[self init]) != nil )
{
// [self init] did basic initialization
// do more initialization with param here
iVar = param;
...
I guess you mean:
- (id)initWithParam:(int)param
{
if ( (self=[super init]) != nil )
{
// [super init] did basic initialization
// do more initialization with param here
iVar = param;
...
You can perfectly well call init (or more properly, the designated
initializer, whatever it happens to be) in the same class, as long
as the
super class init (or designated initializer) is called before the
real setup
starts.
You can do what ever you like, but usually initWithParam will not
call init, but the other way around:
init will call initWithParam: and initWithParam: will call
initWithParam:other: which will call the super designated initializer.
Best Regards,
Nir Soffer
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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