I have this code working fine in swift 2.2
let arrayNib = Bundle.main.loadNibNamed("VehicleDetailsTableViewCell", owner: nil, options: nil) as! NSArray
While in swift 3.0 code gives me error
Cannot convert value of [Any]? to type NSArray in coercion
try this
let arrayNib = Bundle.main.loadNibNamed("VehicleDetailsTableViewCell", owner: nil, options: nil)! as [Any]
print (arrayNib)
I can use it like
let arrayNib = Bundle.main.loadNibNamed("VehicleDetailsTableViewCell", owner: nil, options: nil)
It gives me array of [Any?].
Error is pretty explicit.
You're trying convert Optional<T>
to say U
.
While T
is castable to U
, Optional<T>
is not .
If you want you may cast Optional<T>
to Optional<U>
. Like in your case [Any]?
to NSArray?
.
But I strongly recommend to use Swift
array and add some real types.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.