Pablo Clsn Pablo Clsn - 7 months ago 52
Swift Question

OSX Swift cannot assign value of type string to type NSTextFieldCell

Hi I want to make a timer to shutdown my mac, I have this code :

@IBOutlet weak var valueofSlider: NSTextFieldCell! //label textfield

@IBAction func valueChange(sender: NSSlider) {
var x :Double = sender.doubleValue
valueofSlider = "x"
}


and i got the error : cannot assign value of type String to type NSTextFieldCell

Answer

what is valueOfSlider? The error you are getting suggests that it's an NSTextFieldCell.

You should hook your outlet to the text field, not the text field cell.

The code would be something like this:

myTextField.stringValue = "\(x)"

Or better yet

myTextField.stringValue = String(format: "%.1f", x)