• 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
Re: basic singleton pattern
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Prev by Date: Re: Non collapsable NSSplitView
  • Next by Date: Re: Multiple Windows for documents in Core Data Document files
  • Previous by thread: Re: basic singleton pattern
  • Next by thread: Bindings and the selected object
  • Index(es):
    • Date
    • Thread