Re: Table View/Array Troubles
Re: Table View/Array Troubles
- Subject: Re: Table View/Array Troubles
- From: Bob Warwick <email@hidden>
- Date: Fri, 13 Jun 2008 03:50:04 -0300
On 13-Jun-08, at 2:21 AM, Kyle Sluder wrote:
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
Of course you're correct here, and right to be absolutely pedantic in
regards to how to write an init method properly. In the case of the
original question, NoteController and Note were both subclasses of
NSObject which I believe should behave as expected in the my example.
To indulge my own curiosity, in a case like this where you know the
behaviour of the superclass like NSObject, is there any advantage to
doing it Kyle's way as opposed to my example?
-Bob Warwick
_______________________________________________
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