@@ -131,20 +131,21 @@ func _bridgeStringToKeyPath(_ keyPath:String) -> AnyKeyPath? {
131
131
return __KVOKeyPathBridgeMachinery. _bridgeKeyPath ( keyPath)
132
132
}
133
133
134
- // NOTE: older overlays called this NSKeyValueObservation. The two must
135
- // coexist, so it was renamed. The old name must not be used in the new
136
- // runtime.
137
- public class _NSKeyValueObservation : NSObject {
134
+ // NOTE: older overlays called this NSKeyValueObservation. We now use
135
+ // that name in the source code, but add an underscore to the runtime
136
+ // name to avoid conflicts when both are loaded into the same process.
137
+ @objc ( _NSKeyValueObservation)
138
+ public class NSKeyValueObservation : NSObject {
138
139
139
140
@nonobjc weak var object : NSObject ?
140
141
@nonobjc let callback : ( NSObject , NSKeyValueObservedChange < Any > ) -> Void
141
142
@nonobjc let path : String
142
143
143
144
//workaround for <rdar://problem/31640524> Erroneous (?) error when using bridging in the Foundation overlay
144
- @nonobjc static var swizzler : _NSKeyValueObservation ? = {
145
- let bridgeClass : AnyClass = _NSKeyValueObservation . self
145
+ @nonobjc static var swizzler : NSKeyValueObservation ? = {
146
+ let bridgeClass : AnyClass = NSKeyValueObservation . self
146
147
let observeSel = #selector( NSObject . observeValue ( forKeyPath: of: change: context: ) )
147
- let swapSel = #selector( _NSKeyValueObservation . _swizzle_me_observeValue ( forKeyPath: of: change: context: ) )
148
+ let swapSel = #selector( NSKeyValueObservation . _swizzle_me_observeValue ( forKeyPath: of: change: context: ) )
148
149
let rootObserveImpl = class_getInstanceMethod ( bridgeClass, observeSel)
149
150
let swapObserveImpl = class_getInstanceMethod ( bridgeClass, swapSel)
150
151
method_exchangeImplementations ( rootObserveImpl, swapObserveImpl)
@@ -153,7 +154,7 @@ public class _NSKeyValueObservation : NSObject {
153
154
154
155
fileprivate init ( object: NSObject , keyPath: AnyKeyPath , callback: @escaping ( NSObject , NSKeyValueObservedChange < Any > ) -> Void ) {
155
156
path = _bridgeKeyPathToString ( keyPath)
156
- let _ = _NSKeyValueObservation . swizzler
157
+ let _ = NSKeyValueObservation . swizzler
157
158
self . object = object
158
159
self . callback = callback
159
160
}
@@ -162,7 +163,7 @@ public class _NSKeyValueObservation : NSObject {
162
163
object? . addObserver ( self , forKeyPath: path, options: options, context: nil )
163
164
}
164
165
165
- ///invalidate() will be called automatically when an _NSKeyValueObservation is deinited
166
+ ///invalidate() will be called automatically when an NSKeyValueObservation is deinited
166
167
@objc public func invalidate( ) {
167
168
object? . removeObserver ( self , forKeyPath: path, context: nil )
168
169
object = nil
@@ -187,13 +188,13 @@ public class _NSKeyValueObservation : NSObject {
187
188
188
189
extension _KeyValueCodingAndObserving {
189
190
190
- ///when the returned _NSKeyValueObservation is deinited or invalidated, it will stop observing
191
+ ///when the returned NSKeyValueObservation is deinited or invalidated, it will stop observing
191
192
public func observe< Value> (
192
193
_ keyPath: KeyPath < Self , Value > ,
193
194
options: NSKeyValueObservingOptions = [ ] ,
194
195
changeHandler: @escaping ( Self , NSKeyValueObservedChange < Value > ) -> Void )
195
- -> _NSKeyValueObservation {
196
- let result = _NSKeyValueObservation ( object: self as! NSObject , keyPath: keyPath) { ( obj, change) in
196
+ -> NSKeyValueObservation {
197
+ let result = NSKeyValueObservation ( object: self as! NSObject , keyPath: keyPath) { ( obj, change) in
197
198
let notification = NSKeyValueObservedChange ( kind: change. kind,
198
199
newValue: change. newValue as? Value ,
199
200
oldValue: change. oldValue as? Value ,
0 commit comments