I have a function that returns "Any?" but in my particular instance, I know that it should return a custom "Tuple2" object. But since the Tuple2 is part of a separate Swift plugin, I cannot access the struct directly. I have a duplicate of that struct in my main swift code and I'm trying to cast the "Any?" result to my duplicate struct. But I cannot convince the compiler that such a cast is allowed.
Any ideas on how to get around this?
An example that outlines the problem in a single file is as follows.
typealias Scalar = Double
//~~~~~~ THIS HAPPENS IN THE PLUGIN ~~~~~~
struct Tuple2 {
public var x0: Scalar
public var x1: Scalar
public init(_ x0:Scalar, _ x1:Scalar) {
self.x0 = x0
self.x1 = x1
}
}
let A = Tuple2(1.0,2.0)
let B = A as! Any?
//~~~~~~ THIS HAPPENS IN MY CODE ~~~~~~
struct TupleTwo {
public var x0: Scalar
public var x1: Scalar
public init(_ x0:Scalar, _ x1:Scalar) {
self.x0 = x0
self.x1 = x1
}
}
let C = B as! TupleTwo //Error thrown here
print("x0:\(C.x0) x1:\(C.x1)")