@@ -1168,28 +1168,25 @@ struct TargetClassMetadata : public TargetAnyClassMetadata<Runtime> {
1168
1168
Description = description;
1169
1169
}
1170
1170
1171
- // / Is this class an artificial subclass, such as one dynamically
1172
- // / created for various dynamic purposes like KVO?
1173
- //
1174
1171
// [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
1172
//
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.
1173
+ // Using Objective-C runtime, KVO can modify object behavior without needing
1174
+ // to modify the object's code. This is done by dynamically creating an
1175
+ // artificial subclass of the the object's type.
1176
+ //
1177
+ // The isa pointer of the observed object is swapped out to point to
1178
+ // the artificial subclass, which has the following properties:
1179
+ // - Setters for observed keys are overridden to additionally post
1180
+ // notifications.
1181
+ // - The `-class` method is overridden to return the original class type
1182
+ // instead of the artificial subclass type.
1186
1183
//
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.
1184
+ // For more details, see:
1185
+ // https://www.mikeash.com/pyblog/friday-qa-2009-01-23.html
1186
+
1187
+ // / Is this class an artificial subclass, such as one dynamically
1188
+ // / created for various dynamic purposes like KVO?
1189
+ // / See [NOTE: Dynamic-subclass-KVO]
1193
1190
bool isArtificialSubclass () const {
1194
1191
assert (isTypeMetadata ());
1195
1192
return Description == nullptr ;
0 commit comments