• 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: do you init your instance variables in init method or outside the class?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: do you init your instance variables in init method or outside the class?


  • Subject: Re: do you init your instance variables in init method or outside the class?
  • From: Kyle Sluder <email@hidden>
  • Date: Wed, 18 Jul 2012 08:54:36 -0700

On Jul 18, 2012, at 1:27 AM, Uli Kusterer <email@hidden> wrote:

> On 18.07.2012, at 09:09, Lee Ann Rucker wrote:
>> In init, and only when they need it. They're all initialized to nil, which is a perfectly reasonable value for an instvar to have; there's very rarely a reason to do anything like
>>
>> fly2never wrote:
>>>   name = [NSString string];
>>
>> because sending a method to nil is perfectly safe, unlike C++.
>
> Ah! No! That's not a blanket guarantee! It is only valid for methods that return void, integer types or pointers. If your method returns a struct and you send it to NIL, you get garbage back.

The restrictions have gotten a lot less severe lately: http://developer.apple.com/library/ios/documentation/cocoa/conceptual/objectivec/Chapters/ocObjectsClasses.html (see "Sending Messages to Nil")

Floating-point-returning message to nil has been safe since 10.5, I believe.

As of 10.7, struct-returning message to nil is also nil-safe if the return value fits in registers.

--Kyle Sluder
_______________________________________________

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: 
 >Re: do you init your instance variables in init method or outside the class? (From: Lee Ann Rucker <email@hidden>)
 >Re: do you init your instance variables in init method or outside the class? (From: Uli Kusterer <email@hidden>)

  • Prev by Date: Re: NSArrayController not rearranging correctly
  • Next by Date: NSTokenField: "value" binding hijacks down-arrow key
  • Previous by thread: Re: do you init your instance variables in init method or outside the class?
  • Next by thread: Re: do you init your instance variables in init method or outside the class?
  • Index(es):
    • Date
    • Thread