I am getting the following Swift Compiler Warning:
Expression implicitly coerced from 'UILabel?' to Any
In addition I found the following messages:
<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
But I am not exactly sure why.
This is the code where I use the 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)
}
...
}
}
What am I doing wrong? Or how can I safely mute the compiler?
Thanks