Re: Table View/Array Troubles
Re: Table View/Array Troubles
- Subject: Re: Table View/Array Troubles
- From: "Kyle Sluder" <email@hidden>
- Date: Fri, 13 Jun 2008 01:21:47 -0400
On Thu, Jun 12, 2008 at 2:00 AM, Bob Warwick <email@hidden> wrote:
> Calling the NSMutableArray convenience method array will return an
> autoreleased object. You should do this instead:
>
> - (id) init
> {
> [super init];
> myNotes = [[NSMutableArray alloc] init];
> return self;
> }
Actually, it should really be like this (I've been pedantically explicit):
- (id)init
{
self = [super init];
if(self != nil)
{
myNotes = [[NSMutableArray alloc] init];
}
return self;
}
Note that -init is NOT required to return the same object that "self"
refers to. Therefore it is always required that you re-assign self in
your overridden initializer if you need to access it, and you must
return that modified self*.
--Kyle Sluder
* Please note that this is the common case. If you're implementing
the singleton pattern, for example, you would override -init
differently. And there are other cases like class clusters where you
will instead be returning different objects from -init that super's
implementation returns. But these are Very Advanced Topics(TM).
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please 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