I'm working to convert an iOS Obj-C project to Swift a class at a time. One Obj-C class involved the creation of an NSArray with even elements descriptive NSStrings and odd elements NSNumbers. Not a great piece of design in retrospect but perfectly valid and it did the job. I've converted this to Swift:
let coins = ["1p", 0.01 , "2p" , 0.02 , "5p" , 0.05 , "10p" , 0.10 , "20p" , 0.20 , "50p" , 0.50 , "99p" , 0.99 , "£1" , 1.00 , "£2" , 2.00 , "£5" , 5.00 , "£9.99" , 9.99 , "£10" , 10.00 , "£20" , 20.00]
I do realise that Swift enforces a single type in a one-dimensional array, so we wouldn't so much be talking an array of multiple types as an array of a flexible type - I expected it would infer AnyObject.
I never got to find out however, because it seems this line is an Xcode killer. In my overall project it causes indexing to hang, quickly becoming unresponsive and eventually consuming all system memory. Even this single line of code pasted into the init of a UIView subclass added to a blank single view application causes Xcode to hang on attempting to build in a similar fashion (i'm curious if others have the same experience).
Is there any legitimacy to what i'm attempting here, given that it is compilable code. If so, have I stumbled upon a Swift bug, or perhaps failed to do something vital to allow this to work. I can obviously find a far better way to go about doing what I want, particularly in Swift, but I don't think arrays of multiple types are so rarely seen in Obj-C that this isn't worth understanding further.
let coins : AnyObject[] = ["1p", 0.01, ...?let coins: AnyObject[]andlet coins: Array<AnyObject>.Array<Any>.convertFromArrayLiteral(1,1.2,"x")Any, but I'm not sure if that should compile at all due to Swift's strict type nature