• 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: Creating shared classes
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Creating shared classes


  • Subject: Re: Creating shared classes
  • From: Art Isbell <email@hidden>
  • Date: Wed, 18 Jul 2001 12:49:19 -1000

On Wednesday, July 18, 2001, at 07:46 AM, Brendan Younger wrote:

/// UserSession.m

#import "UserSession.h"

static UserSession* mainUserSession = nil;

@implementation UserSession

- (id)init {
return [super init];
}

Designing a singleton class can be a little tricky. As long as everyone invokes sharedUserSession, things are cool as is. But maybe you want to ensure a singleton if someone invokes [[UserSession alloc] init]. In this case, you'd want init to check for the existence of mainUserSession. If it exists, you'd need to release self and set self to mainUserSession. If mainUserSession doesn't exist, then set mainUserSession to self.

You might also want to prevent the singleton object from being (auto)released. If so, you'd need to override release and autorelease to do nothing.

But you should implement dealloc to clean up. It would need to set mainUserSession to nil as well.

Art Isbell
Apple iServices Technical Support
http://www.apple.com/iservices/webobjectssupport/
+1-808-591-0836


References: 
 >Re: Creating shared classes (From: Brendan Younger <email@hidden>)

  • Prev by Date: Re: Oops, I stand corrected. (was: Collection of Cocoa & objc questions from a "newbie")
  • Next by Date: Re: Oops, I stand corrected. (was: Collection of Cocoa & objc questions from a "newbie")
  • Previous by thread: Re: Creating shared classes
  • Next by thread: Re: Creating shared classes
  • Index(es):
    • Date
    • Thread