Re: clarification regarding properties
Re: clarification regarding properties
- Subject: Re: clarification regarding properties
- From: Nick Zitzmann <email@hidden>
- Date: Fri, 27 Mar 2009 10:38:38 -0600
On Mar 27, 2009, at 10:24 AM, WT wrote:
foo = whatever
just sets the value of foo to the value of whatever, but
self.foo = whatever
actually calls the method setFoo: with whatever as its argument.
This difference is important because the setter method might do some
necessary memory management which the simple unqualified assignment
never does.
Is my understanding correct?
If it is, this would be a major gotcha for Java developers new to
Obj-C.
Correct; ObjC does things the other way around from Java and C#. This
is because ObjC is a true superset of C, and C is of course purely
procedural, and Java and C# are not supersets of C and can do things
differently.
Also, this means that it's best *always* to use the qualified
assignment for properties, since there's a chance that a property
might be changed from assigned to retained or copied (or from
nonatomic to "atomic").
Not always. If you're not using GC, then you may need to keep strong
references to objects, or they might be deallocated behind your
object's back, which would not be a very good thing. So I'd recommend
using accessors unless you have a good reason to not do that.
Nick Zitzmann
<http://www.chronosnet.com/>
_______________________________________________
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