@@ -1170,6 +1170,26 @@ struct TargetClassMetadata : public TargetAnyClassMetadata<Runtime> {
11701170
11711171 // / Is this class an artificial subclass, such as one dynamically
11721172 // / created for various dynamic purposes like KVO?
1173+ //
1174+ // [NOTE: Dynamic-subclass-KVO]
1175+ // To implement Key-Value Observing without any code that notifies the
1176+ // observer, the KVO infrastructure uses dynamic subclassing with Objective-C
1177+ // runtime. When a variable is observed, KVO creates a secret dynamic subclass
1178+ // of that class under the hood which are defined with a prefix of
1179+ // `NSKVONotifying_`.
1180+ //
1181+ // While the observed variables have the type of the dynamic subclass, they
1182+ // must appear like their non-observed counterparts for the front-end user. To
1183+ // achieve this, the dynamic subclass overrides `-class` method which returns
1184+ // the original class type, and internally refers to the subclass in the
1185+ // runtime.
1186+ //
1187+ // In the created subclass, `-set` methods for observed variables are
1188+ // overridden, where the calls to the observer notifications are triggered.
1189+ // KVO only generates one dynamic subclass for each class which overrides all
1190+ // setter methods of variables being observed. That is, setters of variables
1191+ // that are not observed are also not overridden in the dynamic subclass for
1192+ // efficiency.
11731193 bool isArtificialSubclass () const {
11741194 assert (isTypeMetadata ());
11751195 return Description == nullptr ;
0 commit comments