How would I declare an array in Swift which can hold values of any enum String type?
Here's what I want to do:
enum MyEnumType1: String {
case Foo = "foo"
case Bar = "bar"
}
enum MyEnumType2: String {
case Baz = "baz"
}
// ...
// Compiler error: "Type of expression is ambiguous without more context"
var myArray = [ MyEnumType1.Bar, MyEnumType2.Baz ]
// ^ need to declare type here, but not sure of correct syntax
// pass array over to a protocol which will iterate over the array accessing .rawValues
The two enum types are loosely related but definitely distinct and I need to keep the values separated in this instance, so lumping them all together in one enum and declaring the array of type MyAllIncludingEnumType is not desirable.
Or should I just declare an array of Strings and add the rawValues directly?
I could declare the array as [AnyObject] but then I'd have to type check each element before attempting to access the .rawValue, which isn't great either.
Currently I'm only able to use Swift 1.2 on this project, as it's for an app which is already in the App Store and I need to be able to ship updates before Xcode 7 goes GM.
Or is there a cleaner but completely alternate solution to what I want to do?