On Wed, May 19, 2010 at 4:38 AM, Sherm Pendley <sherm.pend...@gmail.com> 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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to