• 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: Double Initialize - is that how it should be?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Double Initialize - is that how it should be?


  • Subject: Re: Double Initialize - is that how it should be?
  • From: Dave Keck <email@hidden>
  • Date: Mon, 16 Mar 2009 16:40:01 -1000

This is expected behavior; from the docs:

The runtime sends initialize to each class in a program exactly one
time just before the class, or any class that inherits from it, is
sent its first message from within the program. (Thus the method may
never be invoked if the class is not used.) The runtime sends the
initialize message to classes in a thread-safe manner. Superclasses
receive this message before their subclasses.

...

If a particular class does not implement initialize, the initialize
method of its superclass is invoked twice, once for the superclass and
once for the non-implementing subclass. If you want to make sure that
your class performs class-specific initializations only once,
implement initialize as in the following example:

@implementation MyClass
+ (void)initialize
{
    if ( self == [MyClass class] ) {
        /* put initialization code here */
    }
}
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please 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:

This email sent to email@hidden

References: 
 >Double Initialize - is that how it should be? (From: Steve Cronin <email@hidden>)

  • Prev by Date: Banding/smoothing problem with drawing angled gradients.
  • Next by Date: How to make letters appear in italics?
  • Previous by thread: Re: Double Initialize - is that how it should be?
  • Next by thread: symlink net
  • Index(es):
    • Date
    • Thread