• 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: Convenience initialisers
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Convenience initialisers


  • Subject: Re: Convenience initialisers
  • From: Andy Lee <email@hidden>
  • Date: Sun, 05 Jul 2009 14:05:35 -0400


On Jul 5, 2009, at 1:40 PM, DKJ wrote:

I'm trying to write one of those convenient class initialisers for one of my objects. On my still-incomplete understanding of these matters, this is what I need to have:

Header:

  + (MyObject *)myObject;

Implementation:

  + (MyObject *)myObject
  {
     return [[[self alloc] init] autorelease];
  }

(I'd have the usual init method in here as well, of course.)

The code above is fine.

Have I done this correctly? (My programme is crashing, but there are plenty of other mistakes I may have made.)

If your code is crashing, avoid guessing as much as possible. *What* is the exception? *Where* is it crashing (run the program in the debugger to see the line of code and the stack trace)? If you put a breakpoint a little before executing that line step through with the debugger, do all your variables have the values you expect?


Frequent causes of crashes are uninitialized *local* variables (*instance* variables are initialized to nil or 0), and over- releasing. To test for over-releasing, use NSZombieEnabled (easy to Google).

But avoid guessing.

--Andy


_______________________________________________

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: 
 >Convenience initialisers (From: DKJ <email@hidden>)

  • Prev by Date: Re: Convenience initialisers
  • Next by Date: Switching Contents of NSView
  • Previous by thread: Re: Convenience initialisers
  • Next by thread: Switching Contents of NSView
  • Index(es):
    • Date
    • Thread