Re: Init with something....
Re: Init with something....
- Subject: Re: Init with something....
- From: Sandro Noel <email@hidden>
- Date: Sun, 10 Dec 2006 09:59:05 -0500
return [self initWithData:defaultData];
Nir, and what would "defaultData" be, nil?
i'm just wondering, the default init does not need any data.
On 10-Dec-06, at 6:09 AM, Nir Soffer wrote:
In this case you probably want something like this:
// Override super designated initializer
- (id)init
{
return [self initWithData:defaultData];
}
- (id)initWithContentsOfFile:(NSString *)filename
{
return [self initWithData:[NSData dataWithContentsOfFile:filename]];
}
// The designated initializer
- (id)initWithData:(NSData *)data
{
self = [super init];
if (self != nil) {
// do something with data
}
return self;
}
You can easily extend this with other init methods as needed. e.g
initWithContentsOfURL. And you don't need to confuse yourself and
others :-)
On Dec 10, 2006, at 05:29, Sandro Noel wrote:
Greetings.
Another one,
when i create a class,
I override the init like this,...
- (id) init{
if ((self = [super init])) {// superclass may return nil
// do init code here.
}
return self;
}
but what if i want to init with a file's content,
I still want to call the init method, for my normal init code to run.
so would this be a good way of doing it ?
of am i over/miss doing it again ....
- (id) initWithFile:(NSString *) path{
if ((self = [self init])) {
[self loadFile:path];
}
return self;
}
again thank you and please forgive, if my questions seem very
beginner type :)
Sandro Noel.
_______________________________________________
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
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