Re: Objective-C default initialization
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