Skip to main content

Implement MasterController interface (iOS/Swift)

KSAsyncEventReceiver
func receive(_ event: KsEvent, withCompletionHandler completionBlock: 
((KsEvent?) -> Void)? = nil) {
let macroEvent = event as? KSMEvent
print("Tag: received event \(type(of: macroEvent))")
for entry in eventListeners {
entry.receive(event, withCompletionHandler: { _ in })
}
if eventListeners.count == 0 {
latestEvents.append(event)
}
}

When events are triggered by the master controller, your app will receive them through this method. It is your adapter's responsibility to pass these events to your controller. In the controller, you can perform specific functionality based on the received events. To ensure your class receives events, make sure to register it as a KSAsyncEventReceiver delegate. This way, any events triggered by the master controller will be received by your class through this delegate.

func register(forEvents: KSAsyncEventReceiver) {
let serialQueue = DispatchQueue(label: "com.kobil.register")
serialQueue.sync {
if eventListeners.count > 0{
for event in eventListeners {
if (event as AnyObject === forEvents as AnyObject){
return
}
}
}
eventListeners.append(forEvents)
}
}