• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Objective-C Instance Variable Names
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Objective-C Instance Variable Names


  • Subject: Re: Objective-C Instance Variable Names
  • From: Jim Correia <email@hidden>
  • Date: Mon, 7 Apr 2008 11:26:28 -0400

On Apr 7, 2008, at 11:12 AM, glenn andreas wrote:

Right, but by having dummy placeholders, they can later rename "_extra" to "_something", and if you have an ivar named "_something" there will be problems. (For that matter, they could also change existing ivar names as well).

No, the breakage doesn't occur at runtime, rather at compile time. And it results in a simple compile error that's very easy to fix.

In the case of renaming _extra to _something, no.

For example, an OS update comes out where a framework has a change like this. Customer upgrades the OS. There is KVC based access to [obj setValue: newValue forKey: @"_something"] (either in your code, or in the updated framework - perhaps in NIB loading). Suddenly there is a collision - KVC will change one of them, even though the hard-coded access methods will still be grabbing their own respective versions.

There is already the possibility of KVC collisions regardless of how you name your iVars.


Consider...

NSBaseClass, and MyClass derived from it.

Targetting 10.4, MyClass has an iVar named mImportantProperty (using m prefix here only for argument's sake), and accessors - setImportantProperty:, -importantProperty.

10.5 comes along and NSBaseClass gets a private iVar named _importantProperty, and the framework code uses KVC to access this property (perhaps through the private accessors - _setImportantProperty:, -_importantProperty.)

My code has violated the don't use the _ prefix for your method names rule.

My code hasn't used the don't use the _ prefix on my iVar names rule/ suggestion/convention.

Yet, I still have the KVC conflict. (And yes, it will probably be a pain in the neck to track down.)

Jim
_______________________________________________

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


  • Follow-Ups:
    • Re: Objective-C Instance Variable Names
      • From: Ricky Sharp <email@hidden>
References: 
 >Objective-C Instance Variable Names (From: Richard Somers <email@hidden>)
 >Re: Objective-C Instance Variable Names (From: Jens Alfke <email@hidden>)
 >Re: Objective-C Instance Variable Names (From: "John C. Randolph" <email@hidden>)
 >Re: Objective-C Instance Variable Names (From: Todd Blanchard <email@hidden>)
 >Re: Objective-C Instance Variable Names (From: "Kyle Sluder" <email@hidden>)
 >Re: Objective-C Instance Variable Names (From: Jens Alfke <email@hidden>)
 >Re: Objective-C Instance Variable Names (From: glenn andreas <email@hidden>)

  • Prev by Date: Re: Objective-C Instance Variable Names
  • Next by Date: Re: Image Processing
  • Previous by thread: Re: Objective-C Instance Variable Names
  • Next by thread: Re: Objective-C Instance Variable Names
  • Index(es):
    • Date
    • Thread