• 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: split up alloc and init?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: split up alloc and init?


  • Subject: Re: split up alloc and init?
  • From: Bill Bumgarner <email@hidden>
  • Date: Mon, 11 Feb 2008 10:06:08 -0800

On Feb 11, 2008, at 12:04 AM, John Terranova wrote:
The self = [super init] discussion is interesting. Here is something related that I came across just before the [super init] discussion started. Basically, is it safe to split up alloc and init?

It is sometimes (keeping in mind that the return value of -init may be different than what you got from +alloc), but not always, safe and the case by case answer is entirely an implementation detail.


Some classes will return a proxy from +alloc that effectively does absolutely nothing -- and complains very loudly if anything else is attempted -- until an appropriate -init... is called which then returns an instance of the most appropriate class given context within the initializer.

Given that it is your own class, you can ensure that it behaves correctly in such a situation. I would recommend against doing so simply because it is a pattern that is rarely used and, when used, is often the source of bugs that can be quite baffling.

b.bum

_______________________________________________

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: 
 >split up alloc and init? (From: John Terranova <email@hidden>)

  • Prev by Date: Re: NSTextView shared state magic?
  • Next by Date: Re: easily search Address Book for phone numbers in various formats?
  • Previous by thread: Re: split up alloc and init?
  • Next by thread: re: split up alloc and init?
  • Index(es):
    • Date
    • Thread