class MainWindowController: NSWindowController {
static var numberOfTickMarks = 10
@IBOutlet weak var slider: NSSlider!
@IBOutlet weak var labelSlider: NSTextField!
@IBOutlet weak var secureTextField: NSTextField!
@IBOutlet weak var revealTextField: NSTextField!
@IBOutlet weak var checkMe: NSButton!
@IBOutlet weak var showTickMark: NSButton!
override var windowNibName: String? {
return "MainWindowController"
}
var positionSlider: Double = 0{
willSet {
}
didSet {
if positionSlider > oldValue {
labelSlider.stringValue = "Slider goes\n up!"
} else {
labelSlider.stringValue = "Slider goes\n down!"
}
}
}
var descriptionCheck: String {
return (checkMe.state==NSOnState) ? "Uncheck me" : "Check me"
}
override func windowDidLoad() {
super.windowDidLoad()
resetControls()
}
private func resetControls() {
//slider
labelSlider.stringValue=""
showTickMark.state = NSOnState
slider.doubleValue = 0
self.slider.numberOfTickMarks = MainWindowController.numberOfTickMarks
//check me
checkMe.state = NSOnState
checkMe.title = descriptionCheck
//secure textfield
revealTextField.stringValue = ""
secureTextField.stringValue = ""
secureTextField.placeholderString = "Type in a secret message"
}
@IBAction func adjustSlider(sender: NSSlider) {
self.positionSlider = slider.doubleValue
}
@IBAction func toggleTickMarks(sender: NSButton) {
slider.numberOfTickMarks = sender.tag==0 ? MainWindowController.numberOfTickMarks : 0
}
@IBAction func checkMe(sender: NSButton) {
checkMe.title = self.descriptionCheck
}
@IBAction func resetControls(sender: NSButton) {
self.resetControls()
}
@IBAction func revealSecretMessage(sender: NSButton) {
revealTextField.stringValue = secureTextField.stringValue
}
}