How to set NSButton key Equivalent to NSDownArrowFunctionKey in Swift

How can I set the NSButtonEquivalent key (which is of type String) to the down arrow key in Swift? NSDownArrowFunctionKey is Int.

0


source to share


1 answer


This page in Apple documentation refers to this exact issue. The example they provide is written in Objective-C, the Swift equivalent looks like this:



import Cocoa

@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {

    @IBOutlet weak var window: NSWindow!
    @IBOutlet weak var button: NSButton!

    func applicationDidFinishLaunching(aNotification: NSNotification) {

        var array = [unichar(NSDownArrowFunctionKey)]
        button.keyEquivalent = NSString(characters: array, length: 1)
    }
}

      

+2


source







All Articles