Skip to content

Commit 5d4f3c8

Browse files
committed
[SDK] Rename _NSKeyValueObservation to NSKeyValueObservation in source code.
Keep the _NSKeyValueObservation in the runtime name, since we need to avoid colliding with the name used in the pre-ABI-stable libraries. rdar://problem/44914709
1 parent ca29204 commit 5d4f3c8

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

Darwin/Foundation-swiftoverlay/NSObject.swift

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -131,20 +131,21 @@ func _bridgeStringToKeyPath(_ keyPath:String) -> AnyKeyPath? {
131131
return __KVOKeyPathBridgeMachinery._bridgeKeyPath(keyPath)
132132
}
133133

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 {
138139

139140
@nonobjc weak var object : NSObject?
140141
@nonobjc let callback : (NSObject, NSKeyValueObservedChange<Any>) -> Void
141142
@nonobjc let path : String
142143

143144
//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
146147
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:))
148149
let rootObserveImpl = class_getInstanceMethod(bridgeClass, observeSel)
149150
let swapObserveImpl = class_getInstanceMethod(bridgeClass, swapSel)
150151
method_exchangeImplementations(rootObserveImpl, swapObserveImpl)
@@ -153,7 +154,7 @@ public class _NSKeyValueObservation : NSObject {
153154

154155
fileprivate init(object: NSObject, keyPath: AnyKeyPath, callback: @escaping (NSObject, NSKeyValueObservedChange<Any>) -> Void) {
155156
path = _bridgeKeyPathToString(keyPath)
156-
let _ = _NSKeyValueObservation.swizzler
157+
let _ = NSKeyValueObservation.swizzler
157158
self.object = object
158159
self.callback = callback
159160
}
@@ -162,7 +163,7 @@ public class _NSKeyValueObservation : NSObject {
162163
object?.addObserver(self, forKeyPath: path, options: options, context: nil)
163164
}
164165

165-
///invalidate() will be called automatically when an _NSKeyValueObservation is deinited
166+
///invalidate() will be called automatically when an NSKeyValueObservation is deinited
166167
@objc public func invalidate() {
167168
object?.removeObserver(self, forKeyPath: path, context: nil)
168169
object = nil
@@ -187,13 +188,13 @@ public class _NSKeyValueObservation : NSObject {
187188

188189
extension _KeyValueCodingAndObserving {
189190

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
191192
public func observe<Value>(
192193
_ keyPath: KeyPath<Self, Value>,
193194
options: NSKeyValueObservingOptions = [],
194195
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
197198
let notification = NSKeyValueObservedChange(kind: change.kind,
198199
newValue: change.newValue as? Value,
199200
oldValue: change.oldValue as? Value,

0 commit comments

Comments
 (0)