Skip to content

Commit bb12abf

Browse files
committed
Fix Notification API signatures to match Darwin
1 parent e61b4c3 commit bb12abf

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

Foundation/NSNotification.swift

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ open class NSNotification: NSObject, NSCopying, NSCoding {
2323
}
2424
}
2525

26-
private(set) open var name: Name
26+
private(set) open var name: NSNotification.Name
2727

2828
private(set) open var object: Any?
2929

@@ -33,8 +33,12 @@ open class NSNotification: NSObject, NSCopying, NSCoding {
3333
/* do not invoke; not a valid initializer for this class */
3434
fatalError()
3535
}
36+
37+
public convenience init(name: NSNotification.Name, object: Any?) {
38+
self.init(name: name, object: object, userInfo: nil)
39+
}
3640

37-
public init(name: Name, object: Any?, userInfo: [AnyHashable : Any]? = nil) {
41+
public init(name: NSNotification.Name, object: Any?, userInfo: [AnyHashable : Any]? = nil) {
3842
self.name = name
3943
self.object = object
4044
self.userInfo = userInfo
@@ -169,7 +173,11 @@ open class NotificationCenter: NSObject {
169173
}
170174
}
171175

172-
open func post(name aName: Notification.Name, object anObject: Any?, userInfo aUserInfo: [AnyHashable : Any]? = nil) {
176+
open func post(name aName: NSNotification.Name, object anObject: Any?) {
177+
post(name: aName, object: anObject, userInfo: nil)
178+
}
179+
180+
open func post(name aName: NSNotification.Name, object anObject: Any?, userInfo aUserInfo: [AnyHashable : Any]? = nil) {
173181
let notification = Notification(name: aName, object: anObject, userInfo: aUserInfo)
174182
post(notification)
175183
}
@@ -188,7 +196,7 @@ open class NotificationCenter: NSObject {
188196
})
189197
}
190198

191-
open func addObserver(forName name: Notification.Name?, object obj: Any?, queue: OperationQueue?, usingBlock block: @escaping (Notification) -> Void) -> NSObjectProtocol {
199+
open func addObserver(forName name: NSNotification.Name?, object obj: Any?, queue: OperationQueue?, using block: @escaping (Notification) -> Void) -> NSObjectProtocol {
192200
let object = NSObject()
193201

194202
let newObserver = NSNotificationReceiver()

Foundation/Notification.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public struct Notification : ReferenceConvertible, Equatable, Hashable {
1818
public typealias ReferenceType = NSNotification
1919

2020
/// A tag identifying the notification.
21-
public var name: Name
21+
public var name: Notification.Name
2222

2323
/// An object that the poster wishes to send to observers.
2424
///

Foundation/NotificationQueue.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,12 @@ open class NotificationQueue: NSObject {
7676
removeRunloopObserver(self.asapRunloopObserver)
7777
}
7878

79-
open func enqueue(_ notification: Notification, postingStyle: PostingStyle) {
79+
open func enqueue(_ notification: Notification, postingStyle: NotificationQueue.PostingStyle) {
8080
enqueue(notification, postingStyle: postingStyle, coalesceMask: [.onName, .onSender], forModes: nil)
8181
}
8282

83-
open func enqueue(_ notification: Notification, postingStyle: PostingStyle, coalesceMask: NotificationCoalescing, forModes modes: [RunLoopMode]?) {
83+
open func enqueue(_ notification: Notification, postingStyle: NotificationQueue.PostingStyle,
84+
coalesceMask: NotificationQueue.NotificationCoalescing, forModes modes: [RunLoopMode]?) {
8485
var runloopModes: [RunLoopMode] = [.defaultRunLoopMode]
8586
if let modes = modes {
8687
runloopModes = modes

0 commit comments

Comments
 (0)