Re: Objective-C Instance Variable Names
Re: Objective-C Instance Variable Names
- Subject: Re: Objective-C Instance Variable Names
- From: "Clark Cox" <email@hidden>
- Date: Thu, 3 Apr 2008 09:37:43 -0700
On Thu, Apr 3, 2008 at 9:29 AM, Richard Somers
<email@hidden> wrote:
> There is a common practice of prefixing instance variable names with "_", a
> single underscore character.
>
> 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.
>
> 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. Nowhere when Apple uses properties does it also prefix
> instance variables with an underscore that I can find. Note that
> NSPointerFunctions.h contains some very interesting property examples.
>
> It would appear then that the practice of practice of prefixing instance
> variable names with an underscore character is becoming a historical relic
> of the past.
>
> Any comments?
There's no reason that the property's name need match the instance
variable's name exactly:
@interface MyObject : NSObject {
id _ivar;
}
@property ivar;
@end
@implementation MyObject
@synthesize ivar=_ivar;
@end
--
Clark S. Cox III
email@hidden
_______________________________________________
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