Fwd: retain and don`t retain in accessor methods
Fwd: retain and don`t retain in accessor methods
- Subject: Fwd: retain and don`t retain in accessor methods
- From: Ariel Feinerman <email@hidden>
- Date: Sun, 15 Nov 2009 00:35:56 +0200
Hi,
I need two versions of -initWith ... and -set ... methods of custom timer
class (for example, to prevent the circle references);
Is these correct implementation?
- (id) initWithTarget: (id) theTarget {
return [self initWithTarget: theTarget retain: YES]; // ?
}
- (id) initWithTarget: (id) theTarget retain: (BOOL) theflag {
if (self = [super init]) {
if ([self setTarget: theTarget retain: theflag]) {
time = 1.0 / 1000.0;
[self begin];
}
else
[self release];
}
return self;
}
- (BOOL) setTarget: (id) theTarget {
return [self setTarget: theTarget retain: YES]; // ?
}
- (BOOL) setTarget: (id) theTarget retain: (BOOL) theflag {
if ([theTarget respondsToSelector: @selector(refresh)]) {
if (flag && target)
[target release];
if (theflag)
[theTarget retain];
target = theTarget;
flag = theflag;
return YES;
}
return NO;
}
_______________________________________________
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