Hi there!
I'm at page 346 in Stephen Kochan's brilliant book, "Programming in Objective-C". I will appreciate very much if someone can clarify the following for me:
The interface file, Addressbook.h declares a method called initWithName:
-(AddressBook *) initWithName: (NSString *) name;
I understand this method to return a pointer to an instance of AddressBook.
However, on the implementation file, Addressbook.m it reads:
-(id) initWithName: (NSString *) name
{
self = [super init];
if (self) {
bookName = [[NSString alloc] initWithString: name];
book = [NSMutableArray alloc] init];
}
return self;
}
I have two questions regarding the definition of initWithName:
First, why is it defined as returning an id and not an pointer to an instance to an Addressbook?
Second why do we have to initialise super?
Many thanks in advance.
Olya
I'm at page 346 in Stephen Kochan's brilliant book, "Programming in Objective-C". I will appreciate very much if someone can clarify the following for me:
The interface file, Addressbook.h declares a method called initWithName:
-(AddressBook *) initWithName: (NSString *) name;
I understand this method to return a pointer to an instance of AddressBook.
However, on the implementation file, Addressbook.m it reads:
-(id) initWithName: (NSString *) name
{
self = [super init];
if (self) {
bookName = [[NSString alloc] initWithString: name];
book = [NSMutableArray alloc] init];
}
return self;
}
I have two questions regarding the definition of initWithName:
First, why is it defined as returning an id and not an pointer to an instance to an Addressbook?
Second why do we have to initialise super?
Many thanks in advance.
Olya