Re: ObjC in time-critical parts of the code
Re: ObjC in time-critical parts of the code
- Subject: Re: ObjC in time-critical parts of the code
- From: Greg Titus <email@hidden>
- Date: Sun, 18 Jan 2009 17:36:10 -0800
On Jan 18, 2009, at 5:13 PM, Justin Carlson wrote:
Jean-Daniel Dupas wrote:
>
> Each time you use KVC/KVO.
Hi Jean-Daniel,
Sorry if I misreading this, your response was short - it could mean
a few things. I am inclined to think you were responding to my
question "how often do your subclasses rewrite getters/setters?".
Justin,
Jean-Daniel was referring to the way that Apple has implemented
automatic KVO compatibility. The first time that someone tries to
observe an object of class X with accessor -foo, and -setFoo:, the
framework makes a dynamic subclass of your class X called something
like X_KVO, and reimplements -setFoo: to be something like:
- (void)setFoo:(id)aFoo
{
[self willChangeValueForKey:@"foo"];
[super setFoo:aFoo];
[self didChangeValueForKey:@"foo"];
}
It then replaces the original X class with the X_KVO class (using a
mechanism like -poseAs:) so that all existing X's are now X_KVO's.
This automatic and dynamic subclassability of getters/setters makes
KVO a lot easier to use, because a lot of it happens for you without
any effort on the programmer's part. And, of course, this wouldn't be
possible had the setter been defined non-virtually in a language like C
++. So here's an example of the dynamism being useful for even the
smallest and simplest of methods (that would normally be inlined in a C
++ framework design).
Hope this helps,
- Greg
_______________________________________________
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