• 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: my class initialize is being called multiple times
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: my class initialize is being called multiple times


  • Subject: Re: my class initialize is being called multiple times
  • From: Allan Hsu <email@hidden>
  • Date: Thu, 8 Jun 2006 12:56:07 -0700

The class initializer will be called for every subclass that does not have its own initialize as well. The pattern you need to follow looks something like this:

+ (void)initialize {
	if(self != [MyClass class])
		return;

	(insert code here)
}

This is documented in the NSObject class documentation:
http://developer.apple.com/documentation/Cocoa/Reference/Foundation/ Classes/NSObject_Class/Reference/Reference.html#//apple_ref/occ/clm/ NSObject/initialize


	-Allan
--
Allan Hsu <allan at counterpop dot net>
1E64 E20F 34D9 CBA7 1300  1457 AC37 CBBB 0E92 C779


On Jun 8, 2006, at 12:49 PM, Graham wrote:

I have a class with a class initializer:

+ (void)initialize;

And it getting called multiple times (which is obviously causing problems for me).
How is this possible?
The class does have several subclasses, not that that should matter.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40counterpop.net


This email sent to email@hidden

_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >my class initialize is being called multiple times (From: Graham <email@hidden>)

  • Prev by Date: my class initialize is being called multiple times
  • Next by Date: Re: one file's owner for multiple nib files
  • Previous by thread: my class initialize is being called multiple times
  • Next by thread: Re: Re: my class initialize is being called multiple times
  • Index(es):
    • Date
    • Thread