Can You explain to me what this warning message means?
let x = cell.backgroundView!.layer.sublayers as! [CALayer]
Forced cast from '[CALayer]?' to '[CALayer]' only unwraps optionals; did you mean to use '!'?
Can You explain to me what this warning message means?
let x = cell.backgroundView!.layer.sublayers as! [CALayer]
Forced cast from '[CALayer]?' to '[CALayer]' only unwraps optionals; did you mean to use '!'?
Using a forced cast makes no sense. sublayers
returns an optional array. You should safely unwrap the optional array.
if let sublayers = cell.backgroundView?.layer.sublayers {
// do something with sublayers (which is a non-optional [CALayer])
}
Also notice the use of ?
after backgroundView
instead of !
.
Please spend time learning how to properly use optionals by reading the relevant sections in the Swift book. Otherwise your app is going to crash. See What does "fatal error: unexpectedly found nil while unwrapping an Optional value" mean? for lot of details about that outcome.