Did you try to use Any as type in struct.
Here is a simple illustration (in playground):
struct Test {
var value: Any
}
let v1 = Test(value: 1 as Any)
let v2 = Test(value: true as Any)
let v3 = Test(value: "true" as Any)
let tests = [v1, v2, v3]
var result : Bool
for (i, v) in tests.enumerated() {
if let valueInt = v.value as? Int { print("An Int for v\(i+1)") ; result = valueInt == 1 }
if let valueBool = v.value as? Bool { print("A Bool for v\(i+1)") ; result = valueBool }
if let valueString = v.value as? String { print("A String for v\(i+1)") ; result = valueString == "true" }
}
Which yields:
An Int for v1
A Bool for v2
A String for v3
Topic:
Programming Languages
SubTopic:
Swift
Tags: