• 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
best practices for object instance initialization
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

best practices for object instance initialization


  • Subject: best practices for object instance initialization
  • From: Stuart Malin <email@hidden>
  • Date: Fri, 21 Mar 2008 10:07:33 -1000

I have a class (a subclass of NSObject) that requires several parameters to be properly initialized. I have a -(id) initWithParams... method defined.
I can't have -init invoke -initWithParams (as a designated initializer) because the object instance wouldn't be set up properly. I am wondering what is the best practice regarding -(id) init in such a case.


1) Do I just let -init dangle (so to speak)? and then if I ever forget that the object needs special initialization and instead call - init, the code will end up failing down the line somewhere where those initialization parameters matter...

2) Do I define a -(init) method and have it throw an exception? so that I'll find out right away if some code invokes -init rather than - initWithParams....

3) Is there some way to tell the compiler to ignore the superclasses's -init for the subclass so that I get a compile time error? This would be my preferred outcome.

Thanks in advance for your thoughts,
--Stuart
_______________________________________________

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


  • Follow-Ups:
    • Re: best practices for object instance initialization
      • From: Andy Lee <email@hidden>
  • Prev by Date: Mac Application Developer- iPhone
  • Next by Date: NIB files on 10.1
  • Previous by thread: Mac Application Developer- iPhone
  • Next by thread: Re: best practices for object instance initialization
  • Index(es):
    • Date
    • Thread