Skip to content

[SR-6419] NotificationCenter.addObserver of SCLF with trailing closure syntax cannot be used on Swift 4.0.2 #3786

Closed
@ikesyo

Description

@ikesyo
mannequin
Previous ID SR-6419
Radar None
Original Reporter @ikesyo
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Foundation
Labels Bug
Assignee @ikesyo
Priority Medium

md5: 1cb775e2d2830c261d8a0e8e57a0fbcd

Issue Description:

In Swift 4.0.2 NotificationCenter.addObserver(forName:object:queue:usingBlock🙂 is renamed to addObserver(forName:object:queue:using🙂 and the old API is kept as an obsoleted API. The obsoleted symbol makes it ambiguous to use the API with trailing closure syntax:

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

This is found at Quick/Nimble#481

/home/travis/build/lvsti/MockSix/.build/checkouts/Nimble.git--3756397004363768916/Sources/Nimble/Matchers/PostNotification.swift:18:27: error: ambiguous use of 'addObserver'
        self.token = self.notificationCenter.addObserver(forName: nil, object: nil, queue: nil) { [weak self] n in
                          ^

Foundation.NotificationCenter:9:15: note: found this candidate
    open func addObserver(forName name: Foundation.NSNotification.Name?, object obj: Any?, queue: Foundation.OperationQueue?, usingBlock block: @escaping (Foundation.Notification) -> Swift.Void) -> NSObjectProtocol
              ^

Foundation.NotificationCenter:10:15: note: found this candidate
    open func addObserver(forName name: Foundation.NSNotification.Name?, object obj: Any?, queue: Foundation.OperationQueue?, using block: @escaping (Foundation.Notification) -> Swift.Void) -> NSObjectProtocol
              ^

Usually we don't keep old (pre-renamed) symbols (e.g. #1315 so the obsoleted API should be removed to make it unambiguous.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions