I create a dictionary like this:
["someKey": []]
to pass into a method that's expecting [String, Any], but when I try to use the array value corresponding to "someKey", I get a value that doesn't match 'is [Any]'. In fact, the debugger can't even display what the value is. So I explored some variations:
(lldb) po [].dynamicType
__NSArrayI
(lldb) po [1].dynamicType
Swift.Array<Swift.Int>
(lldb) po ["abc"].dynamicType
Swift.Array<Swift.String>
(lldb) po Array<Any>()
0 elements
(lldb) po Array<Any>().dynamicType
Swift.Array<protocol<>>
(lldb) po Array<AnyObject>().dynamicType
Swift.Array<Swift.AnyObject>
I find the first of these extremely surprising. Indeed if I create the dictionary like this:
["someKey": Array<Any>()]
I no longer get the crash, but I don't understand why the other form should crap out. Is it me or the compiler that's doing something wrong?
Small observation of something you may already know:
// import Foundation // Compile time errors below happens only when not importing Foundation (ie no objc bridging)
let a = ["someKey": []] // Compile error 1: '_' is not convertible to 'StringLiteralConvertible'
// Compile error 2: Type of expression is ambiguous without more context
So Swift will complain and not let you be that unspecific about the element type of the Array, unless Array is bridged to NSArray (as it is when importing eg Foundation)?