我的问题是关于 swift 中的选项。假设我已经定义了以下内容:
if let myCell = cell as? AECell {
if !myCell.someView.hidden{
//how do i use optional on someView, perhaps someView will not exists
}
}
如您所见,如果 someView 为 nil 该怎么办,我如何在此处使用可选值仅在 someView 不为 nil 时执行 if 语句..我尝试了问号:
if !myCell.someView?.hidden
但其语法不正确
最佳答案
if let myCell = cell as? AECell, let someView = myCell.someView {
// someView is unwrapped now
}
关于Swift - 如何使内部属性可选,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33760897/