如何在Swift中将向下箭头键设置NSButton的keyEquivalent(这是一种String类型)? NSDownArrowFunctionKey是一个Int。
答案 0 :(得分:2)
Apple的文档中的page解决了这个问题。他们提供的示例是用Objective-C编写的,Swift等价如下:
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)
}
}