Skip to content

Instantly share code, notes, and snippets.

@akramhussein
Last active August 29, 2015 14:25
Show Gist options
  • Save akramhussein/d989dede3f4dc27d263a to your computer and use it in GitHub Desktop.
Save akramhussein/d989dede3f4dc27d263a to your computer and use it in GitHub Desktop.
Handle Access Switch devices in iOS - Swift
var commands = [UIKeyCommand]()
var onceToken : dispatch_once_t = 0
override var keyCommands : [AnyObject]? {
get {
dispatch_once(&onceToken) {
self.commands = [
UIKeyCommand(input: " ", modifierFlags: nil, action: "spacePressed:"),
UIKeyCommand(input: "\r", modifierFlags: nil, action: "enterPressed:"),
UIKeyCommand(input: "0", modifierFlags: nil, action: "zeroPressed:"),
]
}
return self.commands
}
}
func spacePressed(command: UIKeyCommand)
{
println("Access Switch Space pressed")
}
func enterPressed(command: UIKeyCommand)
{
println("Access Switch Enter pressed")
}
func zeroPressed(command: UIKeyCommand)
{
println("Access Switch Zero pressed")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment