Hi, how can I translate this Swift code to Kotlin?...
# kotlin-native
g
Hi, how can I translate this Swift code to Kotlin?
Copy code
let center = NSWorkspace.shared.notificationCenter
    
    init() {
        center.addObserver(forName: NSWorkspace.didLaunchApplicationNotification,
                            object: nil, // always NSWorkspace
                             queue: OperationQueue.main) { (notification: Notification) in
                                if let app = notification.userInfo?[NSWorkspace.applicationUserInfoKey] as? NSRunningApplication {
                                    if app.bundleIdentifier == "com.apple.Terminal" {
                                        // User just launched the Terminal app; should we be worried?
                                        print("blah")
                                    }
                                }
        }
    }
Currently I have something like
In Kotlin I get different function signature. How can I invoke it?
g
Copy code
class Sample {

    private val center = NSWorkspace.sharedWorkspace.notificationCenter

    init {
        center.addObserverForName(NSWorkspaceDidLaunchApplicationNotification, null, NSOperationQueue.mainQueue) { notification ->
            (notification?.userInfo.orEmpty()[NSWorkspaceApplicationKey] as? NSRunningApplication)?.let { app ->
                when (app.bundleIdentifier) {
                    "com.apple.Terminal" -> {
                        // User just launched the Terminal app; should we be worried?
                        println("blah")
                    }
                }
            }
        }
    }
}
g
Huge thanks