NSKVOSwizzling: Check if underlying class differs

This commit is contained in:
Hugo Melder 2024-12-17 14:44:57 +01:00
parent c80ab1ee32
commit b7d49bd361

View file

@ -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;
}