• 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: What classes have -init?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: What classes have -init?


  • Subject: Re: What classes have -init?
  • From: James Walker <email@hidden>
  • Date: Thu, 11 Feb 2010 10:43:09 -0800

On 2/10/2010 8:38 PM, Quincey Morris wrote:
On Feb 10, 2010, at 12:23 PM, James Walker wrote:

I think at times I've written things like [[NSMutableArray alloc]
init] with no apparent ill effects, but now I notice that the docs for
NSMutableArray and NSArray don't say that there is an init method. The
NSObject docs say that an init method might raise an exception. Is there
some other init rule that I've missed, or have I just gotten lucky?

It's worthwhile keeping this in mind:

	http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/CocoaFundamentals/CocoaObjects/CocoaObjects.html#//apple_ref/doc/uid/TP40002974-CH4-SW3

Particularly:

"When you define a subclass you must be able to identify the
designated initializer of the superclass and invoke it in your
subclass’s designated initializer through a message to super. You
must also make sure that inherited initializers are covered in some
way."

Applying that [conceptually] to NSArray, say, there's no actual luck
involved. If 'init' is a designated initializer, it should be
documented in the class reference and there's no problem. If not,
then NSArray *must* ensure that calling it results in one of its real
designated initializers being called, *or* must produce an
error.

If it produces an error that I'm not expecting, that would be bad. What I was wondering was how I knew whether it would produce an error, other than by just testing on every version of the OS that I care about.


In a previous reply, Henry McGilton pointed out that the NSObject documentation states that its implementation of init does not produce an error. Therefore, any subclass that doesn't override init does not produce an error.
--
James W. Walker, Innoventive Software LLC
<http://www.frameforge3d.com/>
_______________________________________________


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: 
 >What classes have -init? (From: James Walker <email@hidden>)
 >Re: What classes have -init? (From: "Henry McGilton (Boulevardier)" <email@hidden>)
 >Re: What classes have -init? (From: Scott Anguish <email@hidden>)
 >Re: What classes have -init? (From: Quincey Morris <email@hidden>)

  • Prev by Date: Re: Core Data Issue with Binding
  • Next by Date: setWidth pop-up list of NSComboBox
  • Previous by thread: Re: What classes have -init?
  • Next by thread: Re: What classes have -init?
  • Index(es):
    • Date
    • Thread