April 2015
Intermediate to advanced
556 pages
17h 47m
English
NSControl includes the property:
var action: Selector
Notice that the action property is a selector, so to set the action of a control programmatically, you need to create a selector. For example, suppose you had a button playButton and a method play:
var playButton: NSButton
func play(sender: NSButton) {
...
}
To set playButton’s action to be play, you would write:
let playSelector = Selector("play:")
playButton.action = playSelector
The first line initializes a Selector with the string
"play:". The colon is necessary because this selector
is the name of an action method, and action methods always have a
parameter – sender.
Read now
Unlock full access