• 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: Stupid Cocoa question. How can you tell if the object you are looking at is a property or an ivar?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Stupid Cocoa question. How can you tell if the object you are looking at is a property or an ivar?


  • Subject: Re: Stupid Cocoa question. How can you tell if the object you are looking at is a property or an ivar?
  • From: Jens Alfke <email@hidden>
  • Date: Thu, 21 May 2015 10:02:49 -0700

> On May 21, 2015, at 9:28 AM, Alex Zavatone <email@hidden> wrote:
>
> @synthesize thing = _thing;
> Which makes the internal and private ivar to be _thing while the property becomes thing.
> In my case, this helps to uncover where the original code is accessing the ivar as opposed to the property.

I always use this naming convention. Not just for the reason you state, but because it makes it obvious which variables are ivars, i.e. which have object scope and which have local scope. (Yeah, you can make Xcode color them differently, but it’s not as obvious.) I highly recommend it.

> Now that I have a path forward and understand why things are what they are, this brings up the wonderful speed issue of "how much slower is property access vs ivar access”.

Yeah, I think we’ve had some vigorous debates about this topic in the past. And it’s not just about clock cycles, it’s also about code size — that blog post you linked to shows that ivar access is less than half as many instructions, plus the value can be saved in a register and reused. Code size significantly affects performance because of CPU’s limited instruction cache sizes.

In most high level app code it probably doesn’t make much of a difference. Me, I tend to write lower-level code that does things like data storage and database queries, which are often seriously CPU-bound and where shaving off CPU cycles wherever possible does produce real improvements. (Plus, I’m lazy and it’s faster to type “_foo” than “self.foo”.)

—Jens
_______________________________________________

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: Stupid Cocoa question. How can you tell if the object you are looking at is a property or an ivar?
      • From: Graham Cox <email@hidden>
References: 
 >Stupid Cocoa question. How can you tell if the object you are looking at is a property or an ivar? (From: Alex Zavatone <email@hidden>)
 >Re: Stupid Cocoa question. How can you tell if the object you are looking at is a property or an ivar? (From: Eric Wing <email@hidden>)
 >Re: Stupid Cocoa question. How can you tell if the object you are looking at is a property or an ivar? (From: Michael David Crawford <email@hidden>)
 >Re: Stupid Cocoa question. How can you tell if the object you are looking at is a property or an ivar? (From: Alex Zavatone <email@hidden>)
 >Re: Stupid Cocoa question. How can you tell if the object you are looking at is a property or an ivar? (From: Alex Zavatone <email@hidden>)

  • Prev by Date: Re: NSFontPanel swamping the responder chain (and crashing)
  • Next by Date: Disabling auto-synthesis of property accessors.
  • Previous by thread: Re: Stupid Cocoa question. How can you tell if the object you are looking at is a property or an ivar?
  • Next by thread: Re: Stupid Cocoa question. How can you tell if the object you are looking at is a property or an ivar?
  • Index(es):
    • Date
    • Thread