I'll be quick. Here's an outline:
- I'm porting a library to Linux, SourceKittenDaemon.
- The library used to compile in September, after Swift 4.0 was released.
- Now it doesn't. The compiler says that our use of
NotificationCenter.default.addObserver
is ambiguous. Here's the console output:
Compile Swift Module 'SourceKittenDaemon' (8 sources)
/home/felix/Documents/Programming/SKD/SourceKittenDaemon/Sources/SourceKittenDaemon
/home/felix/Documents/Programming/SKD/SourceKittenDaemon/Sources/SourceKittenDaemon/Completer/Completer.swift:98:28: error: ambiguous use of 'addObserver'
NotificationCenter.default.addObserver(
^
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
^
error: terminated(1): /home/felix/Documents/Programming/Binaries/swift/swift-4.0.3-RELEASE/usr/bin/swift-build-tool -f /home/felix/Documents/Programming/SKD/SourceKittenDaemon/.build/debug.yaml main
Here's the thing. This problem is strange, because both functions' signatures are basically the same. I looked up the class, and indeed, both functions exist, but one of them is marked as obsolete:
This file in the corelibs repo: file
@available(*,obsoleted:4.0,renamed:"addObserver(forName:object:queue:using:)")
open func addObserver(forName name: NSNotification.Name?, object obj: Any?, queue: OperationQueue?, usingBlock block: @escaping (Notification) -> Void) -> NSObjectProtocol {
return addObserver(forName: name, object: obj, queue: queue, using: block)
}
open func addObserver(forName name: NSNotification.Name?, object obj: Any?, queue: OperationQueue?, using block: @escaping (Notification) -> Void) -> NSObjectProtocol {
let object = NSObject()
let newObserver = NSNotificationReceiver()
newObserver.object = object
newObserver.name = name
newObserver.block = block
newObserver.sender = _SwiftValue.store(obj)
newObserver.queue = queue
_observersLock.synchronized({
_observers.append(newObserver)
})
return object
}
This problem tells me that somehow the compiler doesn't know that the function is obsolete, and when trying to fit a function to our code finds two candidates and reports an error.
Maybe this only happens on Linux? I've heard from our Mac users that SKD is compiling perfectly on their machines, so that could be it.
Anything I can do to help, please tell me.
Here's the Github thread for if you want more info / try getting the error yourselves.