I'm developing an app which includes Gamecontroller. I'm trying to show the connected controller count, but it´s not working.
Here is my simple code:
import Cocoa
import GameController
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
func applicationDidFinishLaunching(_ aNotification: Notification) {
// Insert code here to initialize your application
// - MARK: Controllers
let controllers = GCController.controllers()
print(controllers.count)
}
func applicationWillTerminate(_ aNotification: Notification) {
// Insert code here to tear down your application
}
}
it always prints 0
What am I doing wrong?
EDIT:
The problem was i mised to add:
let ctr = NotificationCenter.default
ctr.removeObserver(self, name: .GCControllerDidConnect, object: nil)
ctr.removeObserver(self, name: .GCControllerDidDisconnect, object: nil)
To handle when a controller is connected