Skip to content

Commit

Permalink
Merge pull request #483 from Quick/SR-6419-workaround
Browse files Browse the repository at this point in the history
Work around SR-6419
  • Loading branch information
ikesyo committed Nov 18, 2017
2 parents 38c9ab0 + a62e07e commit 1b135a5
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions Sources/Nimble/Matchers/PostNotification.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,32 @@
import Foundation

// A workaround to SR-6419.
extension NotificationCenter {
#if !(os(macOS) || os(iOS) || os(tvOS) || os(watchOS))
#if swift(>=4.0)
#if swift(>=4.0.2)
#else
// swiftlint:disable:next line_length
func addObserver(forName name: Notification.Name?, object obj: Any?, queue: OperationQueue?, using block: @escaping (Notification) -> Void) -> NSObjectProtocol {
return addObserver(forName: name, object: obj, queue: queue, usingBlock: block)
}
#endif
#elseif swift(>=3.2)
#if swift(>=3.2.2)
#else
// swiftlint:disable:next line_length
func addObserver(forName name: Notification.Name?, object obj: Any?, queue: OperationQueue?, using block: @escaping (Notification) -> Void) -> NSObjectProtocol {
return addObserver(forName: name, object: obj, queue: queue, usingBlock: block)
}
#endif
#else
func addObserver(forName name: Notification.Name?, object obj: Any?, queue: OperationQueue?, using block: @escaping (Notification) -> Void) -> NSObjectProtocol {
return addObserver(forName: name, object: obj, queue: queue, usingBlock: block)
}
#endif
#endif
}

internal class NotificationCollector {
private(set) var observedNotifications: [Notification]
private let notificationCenter: NotificationCenter
Expand All @@ -15,10 +42,11 @@ internal class NotificationCollector {
}

func startObserving() {
self.token = self.notificationCenter.addObserver(forName: nil, object: nil, queue: nil) { [weak self] n in
// swiftlint:disable:next line_length
self.token = self.notificationCenter.addObserver(forName: nil, object: nil, queue: nil, using: { [weak self] n in
// linux-swift gets confused by .append(n)
self?.observedNotifications.append(n)
}
})
}

deinit {
Expand Down

0 comments on commit 1b135a5

Please sign in to comment.