You can do it:
let things: [Any] = [intThing, stringThing]
Thingnot a valid type. Thing<String>is a type, but Thing<Int>is a different type, and you cannot mix different types inside an array.
Did you notice that it does let things: [Thing]n't even compile?
I think what you are probably trying to do would be better than an enumerated server with related values.
struct MyStruct<T> {
let property: T
init(property: T) {
self.property = property
}
}
enum Thing {
case int(Int)
case string(String)
case intStruct(MyStruct<Int>)
}
let myInt = Thing.int(2)
let myString = Thing.string("string")
let myIntStruct = Thing.intStruct(MyStruct<Int>(property: 3))
switch myIntStruct {
case let .int(value):
print("have a int: \(value)")
case let .string(value):
print("have a string: \(value)")
case let.intStruct(value):
print("have a intStruct\(value)")
}
let things: [Thing] = [myInt, myString, myIntStruct]
enum trick here
Plist EntityType.
- , . MyStruct, , MyStruct<Int> . , , MyStruct.
.
, . , , T, T , Thing .