Theocacao
Leopard
Design Element
Comment on "New Objective-C Tutorial"
by Scott Stevenson — May 29
@Joe: Specifically, I'm having trouble understanding the difference between retain and assign in property declarations.

If the instance variable is called "myName", assign would do something roughly equivalent to this:
myName = newName;

Retain would do this:
[myName autorelease]; myName = [newName retain];

Copy would do this:
[myName autorelease]; myName = [newName copy];

This isn't necessarily the exact code that gets generated, but it has the same basic effect.

You also asked if the retain keyword would be the equivalent of "[[caption setCaption:newCaption]retain];". The answer is no, but I'm not sure how to quickly explain why that is the case. I hope the above clears that up.

If you have garbage collection on, assign and retain are the same thing.
Back to "New Objective-C Tutorial"
Design Element

Copyright © Scott Stevenson 2004-2015