Re: Regarding MVC design pattern
Re: Regarding MVC design pattern
- Subject: Re: Regarding MVC design pattern
- From: Kyle Sluder <email@hidden>
- Date: Wed, 19 May 2010 10:12:59 -0700
On Wed, May 19, 2010 at 4:38 AM, Sherm Pendley <email@hidden> wrote:
> If you set the ivars directly, as above, the synthesized setters will
> NOT be called. For that to happen, you need to use dot-syntax, like
> this:
But you shouldn't be using accessors in -init or -dealloc anyway. It
makes subclassing fragile. Unless, of course, you make the accessor's
behavior an explicit part of your subclassing contract so both sides
can handle being partially initialized or deallocated. But on the
whole it's just easier not to use accessors in -init and -dealloc.
If you synthesize your ivars, you can get at the ivar using the self-> syntax.
@interface MyClass
@property(retain) id myFoo;
- (id)initWithFoo:(id)aFoo;
@end
@implementation MyClass
@synthesize myFoo;
- (id)initWithFoo:(id)aFoo {
if (!(self = [super init]))
return nil;
self->myFoo = [aFoo retain];
return self;
}
- (void)dealloc {
[self->myFoo release];
[super dealloc];
}
--Kyle Sluder
_______________________________________________
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