• 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
-init is not being called on my custom class
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

-init is not being called on my custom class


  • Subject: -init is not being called on my custom class
  • From: mw <email@hidden>
  • Date: Sun, 09 Feb 2003 09:34:07 -0500

Hello,

I have a custom class called CoreApplication. It is a singleton, and for
some reason, it's -init method isn't being called. Here is some sample code
to help:

// the singleton accessor
+ (id)sharedApplicationModel
{
if (!sharedInstance) {
sharedInstance = [[CoreApplication alloc] init];
}
return sharedInstance;
}

As you can see, sharedInstance is being allocated and initialized. When in
the debugger, stepping into this line puts me into my alloc method (which I
have overridden to make sure that more than one instance of the
CoreApplication class is ever created in the program. But when +alloc
returns self (which it does, like it is supposed to), and control is
returned to +sharedApplicationModel, -init is never called (and there is
some very important code in there that *has* to be executed). Here is
+alloc:

+ (id)alloc
{
if (!sharedInstance) {
self = [super init];
return self;
} else {
return nil;
}
}

And here is -init, if that helps any:

- (id)init
{
if(!sharedInstance) {
NSLog(@"Attempt to initialize CoreApplication without being
allocated first!");
return nil;
} else {
_registrationModule = [[RegistrationModel alloc] init];
}
return self;
}

Also, when +alloc returns self, I already checked that it is a valid pointer
to the correct kind of object (CoreApplicaton).

Does anybody have any ideas? This has totally got me stuck. If there is any
problem with my code, my guess is that it would be in +alloc since I have
never overridden that method before.

TIA,
mw

--
"Software exists to solve your problems. We exist to make the problems."
Microsoft
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Re: Weird problem with array declaration in action
  • Next by Date: Re: cocoa-dev digest, Vol 2 #1919 - 12 msgs
  • Previous by thread: Re: All Keys
  • Next by thread: Re: -init is not being called on my custom class
  • Index(es):
    • Date
    • Thread