Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: basic singleton pattern



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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.