On Sep 23, 2011, at 9:30 PM, Greg Parker wrote: > 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.
Huh. I had always thought that those functions respected @private and @protected, but I just tried it, and you are indeed correct. Thanks. It’s a little disturbing that private instance variables can be altered so easily, but then I suppose the same thing could just as easily be done by a third-party monkeying with the ivar in a category. Charles_______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com