When does an object own its instance variable?
When does an object own its instance variable?
- Subject: When does an object own its instance variable?
- From: Bob Ueland <email@hidden>
- Date: Fri, 17 Aug 2007 03:14:29 -0700 (PDT)
I'm reading Kochan's book "Programming in Objective-C". In chapter 15 he has the following piece of code:
interface AddressCard: NSObject
{
NSString *name;
...
}
-(void) setName: (NSString *) theName;
...
@end
@implementation AddressCard;
-(void) setName: (NSString *) theName
{
name = [[NSString alloc] initWithString: theName];
}
...
@end
Explaining the code he says; Defining the method this way:
-(void) setName: (NSString *) theName
{
name = [NSString stringWithString: theName];
}
would be the incorrect approach because the AddressCard method would not own its name object, NSString would own it. I do not understand it. Could somebody explain what he means?
Thanks Bob
____________________________________________________________________________________
Park yourself in front of a world of choices in alternative vehicles. Visit the Yahoo! Auto Green Center.
http://autos.yahoo.com/green_center/
_______________________________________________
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