• 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: Objective-C default initialization
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Objective-C default initialization


  • Subject: Re: Objective-C default initialization
  • From: "Sherm Pendley" <email@hidden>
  • Date: Fri, 11 Jul 2008 21:19:50 -0400

On Fri, Jul 11, 2008 at 8:10 PM, Greg <email@hidden> wrote:
> I've noticed that objects get initialized to nil if you don't set them, is
> this guaranteed in objective-c?
>
> I've been trying to find documentation from Apple on this but have been
> unable.
>
> In other words, if you have a simple class like this:
>
>> @interface MyClass : NSObject {
>>        id obj;
>> }
>> @end
>
> Then when -init is called is 'obj' *guaranteed*, always, in all versions of
> OS X, to be nil?

Yes, but that's because it's an instance variable. When memory for a
new object is allocated, its ivars are initialized to nil, 0, or 0.0
as appropriate.

On the other hand, local variables are *not* initialized:

-(void) foo {
    id obj;  // This can be anything
}

sherm--

--
Cocoa programming in Perl: http://camelbones.sourceforge.net
_______________________________________________

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: 
 >Objective-C default initialization (From: Greg <email@hidden>)

  • Prev by Date: Re: XCode 3.1 quits each time after launch
  • Next by Date: Re: XCode 3.1 quits each time after launch
  • Previous by thread: Re: Objective-C default initialization
  • Next by thread: Protocol-conforming object does not include retain?
  • Index(es):
    • Date
    • Thread