mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-23 09:04:13 +00:00
NSKVOSwizzling: Check if underlying class differs
This commit is contained in:
parent
c80ab1ee32
commit
b7d49bd361
1 changed files with 12 additions and 1 deletions
|
@ -666,6 +666,8 @@ void
|
|||
_NSKVOEnsureKeyWillNotify(id object, NSString *key)
|
||||
{
|
||||
char *rawKey;
|
||||
Class cls;
|
||||
Class underlyingCls;
|
||||
|
||||
// Since we cannot replace the isa of tagged pointer objects, we can't swizzle
|
||||
// them.
|
||||
|
@ -674,8 +676,17 @@ _NSKVOEnsureKeyWillNotify(id object, NSString *key)
|
|||
return;
|
||||
}
|
||||
|
||||
cls = [object class];
|
||||
underlyingCls = [object _underlyingClass];
|
||||
// If cls differs from underlyingCls, object is actually a proxy.
|
||||
// Retrieve the underlying object with KVC.
|
||||
if (cls != underlyingCls)
|
||||
{
|
||||
object = [object valueForKey: @"self"];
|
||||
}
|
||||
|
||||
// A class is allowed to decline automatic swizzling for any/all of its keys.
|
||||
if (![[object class] automaticallyNotifiesObserversForKey: key])
|
||||
if (![underlyingCls automaticallyNotifiesObserversForKey: key])
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue