Currently, in Swift 3, there are 2 ways to write dictionary types. These are Dictionary<String, Any>
and [String: Any]
. I know that the former is compatible with Objective-C key/value coding and the latter is not but other than this are there any major differences between them or any performance implications I should be aware of?
I am currently swaying towards using the former for its Obj-C key/val compatibility but please warn me if this is a slippery slope.
I suppose the same could be said for Array<String>
and [String]
too?
Dictionary<String, Any>
and [String: Any]
, Array<String>
and [String]
are same. There is no difference at all.
Dictionary and [String: Any] are different syntax for the same thing. If you want key-value coding you can use NSDictionary or NSArray.
var swiftarray: Array = []
// Fill the array with objects
var array: NSArray = (swiftarray as NSArray).valueForKeyPath("key.path") as NSArray
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With