Swift 警告信息不明确
Swift warning message not clear
你能给我解释一下这个警告消息的意思吗?
let x = cell.backgroundView!.layer.sublayers as! [CALayer]
Forced cast from '[CALayer]?' to '[CALayer]' only unwraps optionals; did you mean to use '!'?
使用强制转换没有意义。 sublayers
returns 一个可选数组。您应该安全地打开可选数组。
if let sublayers = cell.backgroundView?.layer.sublayers {
// do something with sublayers (which is a non-optional [CALayer])
}
还要注意在 backgroundView
之后使用 ?
而不是 !
。
请花时间阅读 relevant sections in the Swift book. Otherwise your app is going to crash. See 了解有关该结果的大量详细信息,学习如何正确使用可选值。
你能给我解释一下这个警告消息的意思吗?
let x = cell.backgroundView!.layer.sublayers as! [CALayer]
Forced cast from '[CALayer]?' to '[CALayer]' only unwraps optionals; did you mean to use '!'?
使用强制转换没有意义。 sublayers
returns 一个可选数组。您应该安全地打开可选数组。
if let sublayers = cell.backgroundView?.layer.sublayers {
// do something with sublayers (which is a non-optional [CALayer])
}
还要注意在 backgroundView
之后使用 ?
而不是 !
。
请花时间阅读 relevant sections in the Swift book. Otherwise your app is going to crash. See