Array with string and number

arrays, swift

Solution

Yes, you can do this in Swift as well.

var arr: Array<Any> = ["string1", "string2", 123, 456]

An array of type `Any` can hold Strings, Ints and other objects and structs.

Problem

In objective c it is easy to create a heterogeneous array like this: ``` NSArray *myArray = @["String1", "String2", 123, 456]; ``` Is there any way to create such an array in swift? If yes then how? Note: I tried similar statement in swift - ``` var arr = ["string1", "string2", 123, 456] ``` but it is giving compilation error: ``` Playground execution failed: error: <REPL>:124:17: error: cannot convert the expression's type 'Array' to type 'IntegerLiteralConvertible' var arr : Any = ["string1", "string2", 123, 456] ```

Original source