• 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: Enrique Zamudio <email@hidden>
  • Date: Wed, 18 Jul 2001 17:44:52 -0500
  • Organization: Nasoft

You're doing it the wrong way (of course you know this, or you wouldn't
be posting to the list, right?)

You are assigning every new instance of UserSession to the
mainUserSession variable. And in your +sharedUserSession you're just
returning the variable. But calling that method (which is a class
method) will not create any instances. You should have it like this
instead:

@implementation UserSession

static UserSession *mainUserSession = nil;

- init
{ //does nothing really
[super init];
return self;
}

+ sharedUserSession
{
if (mainUserSession == nil)
mainUserSession = [[UserSession alloc] init];
return mainUserSession;
}

...

This way, the first time +sharedUserSession is called, it will create a
new instance of UserSession and store it in the mainUserSession is
variable (which is inside the class) and return it. On subsequent calls,
it only returns that object.

eZL


  • Prev by Date: Desktop database
  • 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: Toolbars in sheets?
  • Index(es):
    • Date
    • Thread