• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
basic singleton pattern
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: basic singleton pattern
      • From: mmalc Crawford <email@hidden>
  • Prev by Date: Re: "Live" support for aggregate functions (@min, @max, etc)
  • Next by Date: Re: basic singleton pattern
  • Previous by thread: Re: Practical tutorial
  • Next by thread: Re: basic singleton pattern
  • Index(es):
    • Date
    • Thread