Event based triggering in Swift