Re: Why does Xcode define IBOutlet with @synthesize?
Re: Why does Xcode define IBOutlet with @synthesize?
- Subject: Re: Why does Xcode define IBOutlet with @synthesize?
- From: Greg Parker <email@hidden>
- Date: Fri, 23 Sep 2011 19:30:11 -0700
On Sep 23, 2011, at 7:21 PM, Charles Srstka wrote:
> On Sep 23, 2011, at 6:06 PM, Greg Parker wrote:
>>
>> Nib connection on iOS uses KVC. Nib connection on OS X does not use KVC itself, but it does use a similar "call method if it exists, set ivar directly if it does not" algorithm.
>
> But how does that work? If I make the IBOutlet an ivar, make it @private, and have +accessInstanceVariablesDirectly return NO, trying to access this ivar directly from another object causes a compiler error, and trying to access it via KVC throws a “not key value coding-compliant for the key <outlet name>” exception. Yet the nib loading mechanism is still able to set the ivar. I’ve always been curious about why exactly this works.
On OS X, nib connection does not use KVC. Since it's not using KVC, it pays no attention to KVC machinery like +accessInstanceVariablesDirectly.
The OS X nib connection implementation calls object_setInstanceVariable(). This function, like all of the runtime's introspection functions, ignores compile-time access controls.
--
Greg Parker email@hidden Runtime Wrangler
_______________________________________________
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