Re: basic singleton pattern
Re: basic singleton pattern
- Subject: Re: basic singleton pattern
- From: Gorazd Krosl <email@hidden>
- Date: Sat, 26 May 2007 11:27:23 -0400 (EDT)
On May 25, 2007, at 12:44 PM, Daniel Child wrote:
Hi Daniel,
You are not returning a created object but a reference
to a Singleton class. You should do:
return uniqueInstance;
and not
return self.
Read on class and instance methods in ObjC reference
book on Apple's site.
Regards,
Gorazd
static Singleton *uniqueInstance = nil;
@implementation Singleton
+ (Singleton *) getInstance {
if (uniqueInstance == nil) {
uniqueInstance = [[self alloc] init];
[uniqueInstance setValue: 0];
}
return self;
}
- (void) setValue: (int) newVal {
value = newVal;
}
- (int) value {
return value;
}
@end
Get a sneak peak at messages with a handy reading pane with All new Yahoo! Mail: http://mrd.mail.yahoo.com/try_beta?.intl=ca
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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