The following code does not work in an Xcode Playgrounds or the Swift Playgrounds App on iOS oder macOS. But the same code works when used in an app.
Does anyone know how to get the notifications running in a Playground?
import GameController
import Combine
import SwiftUI
import PlaygroundSupport
PlaygroundPage.current.needsIndefiniteExecution = true
var cancellables = Set<AnyCancellable>()
NotificationCenter.default.publisher(for: NSNotification.Name.GCControllerDidConnect)
.subscribe(on:DispatchQueue.global())
.print()
.receive(on: DispatchQueue.main)
.sink { notification in
print(notification)
}.store(in: &cancellables)
let disConnect = NotificationCenter.default.publisher(for: NSNotification.Name.GCControllerDidDisconnect)
.print()
.subscribe(on:DispatchQueue.global())
.receive(on: DispatchQueue.main)
.sink { value in
print(value)
}.store(in: &cancellables)