我收到以下Swift编译器警告:
Expression implicitly coerced from 'UILabel?' to Any
此外,我发现了以下消息:
<unknown>:0: warning: expression implicitly coerced from 'UILabel?' to Any
<unknown>:0: note: provide a default value to avoid this warning
<unknown>:0: note: force-unwrap the value to avoid this warning
<unknown>:0: note: explicitly cast to Any with 'as Any' to silence this warning
但我不确定为什么。
这是我使用UILabel
class MyCell: UITableViewCell {
var primaryLabel: UILabel!
var secondaryLabel: UILabel!
required init(coder aDecoder: NSCoder) {
fatalError("init(coder:)")
}
init(_ row: myStruct) {
super.init(style: .default, reuseIdentifier: "myId")
primaryLabel = {
let l = UILabel(frame: .zero)
...
l.translatesAutoresizingMaskIntoConstraints = false
return l
}()
self.addSubview(primaryLabel)
if row.subtitle != nil {
secondaryLabel = {
let l = UILabel(frame: .zero)
...
l.translatesAutoresizingMaskIntoConstraints = false
return l
}()
self.addSubview(secondaryLabel)
}
...
}
}
我做错了什么?或者我如何安全地使编译器静音?
由于