Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dictionary<String, Any> vs. [String: Any] [duplicate]

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?

like image 663
Jacob King Avatar asked Mar 10 '23 02:03

Jacob King


2 Answers

Dictionary<String, Any> and [String: Any], Array<String> and [String] are same. There is no difference at all.

like image 175
Parth Adroja Avatar answered Mar 20 '23 21:03

Parth Adroja


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
like image 25
ptoinson Avatar answered Mar 20 '23 23:03

ptoinson