Pablo Clsn Pablo Clsn - 2 years ago 189
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 Source

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)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download