Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ikesyo mannequin opened this issue Nov 17, 2017 · 6 comments
Assignees

Comments

@ikesyo
Copy link
Mannequin

ikesyo mannequin commented Nov 17, 2017

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.

@belkadan
Copy link

belkadan commented Nov 17, 2017

@phausler There was a dup of this for macOS, right?

@ikesyo
Copy link
Mannequin Author

ikesyo mannequin commented Nov 23, 2017

@available(*, obsoleted: 4.0) is not appropriate and @available(swift, obsoleted: 4.0) should be used instead.

@ikesyo
Copy link
Mannequin Author

ikesyo mannequin commented Nov 23, 2017

I was requested to use @available(*, unavailable) instead of @available(swift, obsoleted: 4.0).

@ikesyo
Copy link
Mannequin Author

ikesyo mannequin commented Nov 23, 2017

So the actual issue here is @available(*, obsoleted: 4.0) means iOS 4.0, macOS 4.0, tvOS 4.0, watchOS 4.0 and does not mean Swift 4.0.

@belkadan
Copy link

belkadan commented Nov 27, 2017

That's hilarious. We should definitely be rejecting that!

@alblue
Copy link
Contributor

alblue commented Nov 28, 2017

This has been merged into the master branch, which should be part of the 4.1 release.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants