basic singleton pattern
basic singleton pattern
- Subject: basic singleton pattern
- From: Daniel Child <email@hidden>
- Date: Fri, 25 May 2007 15:44:47 -0400
The following code will not allow me to initialize the uniqueInstance
to 0. Apparently the method is not recognized? I must be missing
something basic. I gave Singleton a single instance variable ("value").
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
This is again "translated" from a Java pattern, though I can't tell
why it is not working. and in particular don't see why I can't apply
the setValue method. Thanks in advance.
_______________________________________________
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