简体   繁体   中英

iOS Learning with Lynda: Getting error can't invoke 'init' with argument of type @lvalue String

I'm trying to follow lynda's (not sure if nonmembers can see it) tutorial on iOS 9 and Swift, but I'm getting an error that doesn't match the screencast. If anyone's familiar, this is the tutorial: "Controlling when tapped numbers should not appear in the calculator"

This is a basic calculator that I'm trying to build. The basic idea is to take number inside a label into a string and then convert back into an number and then putting it back into a string so when pressing the button "0" it won't have multiple zeros on the calculator.

func updateText() {
    let labelInt:Int = Int(labelString)
    --> Cannot invoke 'init' with an argument of type '@lvalue String'
    label.text = "\(labelInt)"
}

in the screencast the error is different:

func updateText() {
    let labelInt:Int = Int(labelString)
    --> Value of optional type 'int?' not unwrapped; did you mean to use '!' or '?'?
    label.text = "\(labelInt)"
}

EDIT: Screenshot

在此处输入图片说明

You need to unwrapped the labelString value with ! sign, so write like,

func updateText() {
    let labelInt:Int = Int(labelString)!
    label.text = "\(labelInt)"
}

Hope this will help you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM