Re: SmartList
Re: SmartList
- Subject: Re: SmartList
- From: Chris Page <email@hidden>
- Date: Thu, 19 Dec 2013 15:53:32 -0800
On Dec 19, 2013, at 2:53 PM, Alex Zavatone <email@hidden> wrote:
Accessing the property directly:
Getting NSBunnies *myBunnies = myAwesomeObject.bunnies; // syntax is: object dot property.
Setting myAwesomeObject.bunnies = [[NSBunnies alloc]initWithMoreBunnies: 5];
Note: These are not necessarily direct access. This syntax will call the getter and setter methods if they exist; otherwise, it will perform direct access. The syntax for direct access is to refer to the ivar on its own (I’ve renamed “bunnies” to “_bunnies” to follow convention):
NSBunnies *myBunnies = _bunnies; // syntax is: object dot property. _bunnies = [[NSBunnies alloc]initWithMoreBunnies: 5];
The key here is that there is no object preceding “_bunnies”—no Objective-C message will be sent—so the compiler looks for a local variable or ivar, then parameters, then globals; ivars are just another variable that’s in scope. Of course, this only works inside methods of a class that has this ivar, and this is intentional: normally, the public interface for a class only exposes accessor methods (or @property declarations) and direct ivar access is a private implementation detail that only that class’s methods should do. By default, @property names the ivar and the getter with the same name and you always access it through the getter, even inside that class’s methods; generally, it should be a special case to use direct ivar access, like when you’re implementing accessors. If you want to use direct ivar access, the convention is to name the ivar with an underscore prefix to make it clear that it’s using direct access, and so that it has a different name from the getter accessor.
-- Chris Page
The other, other AppleScript Chris
|
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden