Re: Objective-C Instance Variable Names
Re: Objective-C Instance Variable Names
- Subject: Re: Objective-C Instance Variable Names
- From: Jens Alfke <email@hidden>
- Date: Thu, 3 Apr 2008 09:45:45 -0700
On 3 Apr '08, at 9:29 AM, Richard Somers wrote:
There is a common practice of prefixing instance variable names with
"_", a single underscore character.
And it's a very good idea to do so, IMHO. (The exact prefix isn't
important, just as long as it's easy to distinguish ivars from local
vars at a glance.)
If Objective-C 2.0 properties are used this would result in dots
followed by underscores when invoking accessor methods with the dot
syntax. Not a desirable situation.
Properties and ivars are not the same thing. Properties are shorthand
for methods, not variables. A property doesn't have to correspond to
any instance variable, or to one with the identical name.
It appears that Apple as of Mac OS 10.5 uses properties only in Core
Animation classes and NSPointerFunctions.h with CALayer.h being the
single biggest user.
They just didn't feel it was worth it to rewrite hundreds of existing
AppKit and Foundation header files replacing all the getter/setter
method declarations with the equivalent "@property"s. It doesn't
really make a difference, because you can still use property syntax
when referring to attributes that have getters or setters — for
example "window.frame" or "string.length". I do it all the time, it
saves typing and keeps me from having to count so many nested brackets.
—Jens
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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