简体   繁体   中英

Expression resolves to an unused property

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if segue.identifier == "toDetails" {
        if let indexPath = sender as? IndexPath {
            if let nextVC = segue.destination as? JobDetailViewController {
                let valueToPass = jobs[indexPath.row].text <- Thread1
                let passUserName = jobs[indexPath.row].addedByUser
                nextVC.jobDetail.text = valueToPass
                nextVC.userLabel.text = passUserName
            }
        }
    }
}

EDIT: I'm now getting "Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value" as an Error.

This is the code of my DestinationVC

@IBOutlet weak var jobDetail: RoundLabel!
@IBOutlet weak var userLabel: UILabel!

var valueToPass: String = ""
var passUserName: String!

override func viewDidLoad() {
    super.viewDidLoad()
    jobDetail.text = valueToPass
    userLabel.text = passUserName
}
}

Expression resolves to an unused property

This error means, that you wrote code with reference for some property of some item in jobs array, but you haven't done anything with it (declare some constant, change some variable, etc.)

You probably just wanted to declare Job item for specific row, so you can do it like this

let job = jobs[indexPath.row]

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