I am trying to downcast a multidimensional array property which is required by a protocol in a subclass of the protocol conforming class. However currently the compiler is giving me a an error when I do so. The error is: 'DataClass' is not identical to 'Any'
.
The strange thing is that when the property is reduced to a single dimensional array the error disappears. Could this be a bug with Swift or am I not understanding how Swift handles the typing of multidimensional arrays?
This has been around since Swift 1.0, so I feel like I am missing something obvious here...
I have reproduced my situation in an easily testable code snippet:
protocol MyProtocol {
var myProperty: ([[Any]])! { get set }
func myFuncReturn() -> Any
func myFuncParam(param: Any)
}
class MyClass: MyProtocol {
var myProperty: ([[Any]])!
init(myProperty: ([[Any]])!) {
self.myProperty = myProperty
}
func myFuncReturn() -> Any {
return myProperty[0][0]
}
func myFuncParam(param: Any) { }
}
class MySubclass: MyClass {
var myPropertyOver: ([[DataClass]])! {
return myProperty as? ([[DataClass]])
}
init() {
super.init(myProperty: [[DataClass()]])
}
}
class DataClass { }
Thanks for your help!