When trying to add the example code from WWDC 2020 to my project I get
dyld: lazy symbol binding failed: Symbol not found: _$s2os6LoggerVMa
...
Expected in: /usr/lib/swift/libswiftos.dylib
dyld: lazy symbol binding failed: Symbol not found: _$s2os6LoggerVMa
...
Expected in: /usr/lib/swift/libswiftos.dylib
Code Block import os @available(OSX 10.16, *) let logger = Logger(subsystem: "com.example.Fruta", category: "giftcards") @available(OSX 10.16, *) @NSApplicationMain class AppDelegate: NSObject, NSApplicationDelegate { var window: NSWindow! func applicationDidFinishLaunching(_ aNotification: Notification) { logger.log("logged Message")
I guess the app is running on macOS 10.15. What is happening here is that, since AppDelegate is annotated as NSApplicationMain, it is expected to be available on all deployment targets this app targets. In macOS 10.15, NSApplicationMain() will load the nib, which instantiates the AppDelegate and then runs the applicationDidFinishLaunching() method. Even though AppDelegate has 10.16 only code in it, nib loading will happily instantiate it regardless of the running OS version, which causes this error. Since AppDelegate is marked as only available on 10.16, the compiler doesn’t complain about the use of logger.log.
The solution to this problem is to remove @available(OSX 10.16, *) from AppDelegate and use if #available(OSX 10.16, *) around the log call as shown below. This ensures that AppDelegate can be instantiated in 10.15 as well, but the logging APIs are used only in 10.16
The solution to this problem is to remove @available(OSX 10.16, *) from AppDelegate and use if #available(OSX 10.16, *) around the log call as shown below. This ensures that AppDelegate can be instantiated in 10.15 as well, but the logging APIs are used only in 10.16
Code Block if #available(OSX 10.16, *) { logger.log("logged Message") }