表达式解析为未使用的属性 [英] Expression resolves to an unused property

查看:311
本文介绍了表达式解析为未使用的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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
            }
        }
    }
}

我现在收到线程1:致命错误:在展开可选值时意外发现nil"作为错误.

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

这是我的DestinationVC的代码

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

此错误意味着,您为jobs数组中某项的某些属性编写了引用代码,但您并未对其进行任何操作(声明一些常量,更改某些变量等)

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.)

您可能只想声明特定行的Job项,因此您可以这样做

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

let job = jobs[indexPath.row]

这篇关于表达式解析为未使用的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆