• 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: Jim Correia <email@hidden>
  • Date: Tue, 17 Mar 2009 10:17:31 -0400

On Mar 16, 2009, at 10:21 PM, Steve Cronin wrote:

I use an object in my application called 'appDelegate'; it's a subclass of NSObject.

I instantiate this object in the main Nib file
This object has IBActions for the main menu and since it is -app delegate it is a kind on central dispatcher.


My question is this:
The +initialize is run twice when the app loads:
2009-03-16 20:21:42.690 XYZ[6676:813] *[AppDelegate initialize]
2009-03-16 20:21:42.781 XYZ[6676:813] *[NSKVONotifying_AppDelegate initialize]


Once for the object itself and then again as the instance in the Nib. That's how I read this. Is that wrong?

The specific reason that you got +initialize twice has to do with an implementation detail of automatic KVO.


There are also other reasons that you could get +initialize twice. (For example, a subclass of yours doesn't implement initialize.)

This is discussed in the NSObject documentation, and the pattern to use to avoid "double" initialization is given.

http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/nsobject_Class/Reference/Reference.html#/ /apple_ref/occ/clm/NSObject/initialize

Jim

_______________________________________________

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: Re: Working with weekdays on NSDate, NSDateComponents, NSCalendar and NSValueTransformer
  • Next by Date: NSTableView Drag and Drop doesn't work
  • Previous by thread: Re: Double Initialize - is that how it should be?
  • Next by thread: Re: Double Initialize - is that how it should be?
  • Index(es):
    • Date
    • Thread