How to copy a “Dictionary” in Swift?
问题 How to copy a "Dictionary" in Swift? That is, get another object with same keys/values but different memory address. Furthermore, how to copy an object in Swift? Thanks, 回答1: A 'Dictionary' is actually a Struct in swift, which is a value type. So copying it is as easy as: let myDictionary = ... let copyOfMyDictionary = myDictionary To copy an object (which is a reference type) has a couple of different answers. If the object adopts the NSCopying protocol, then you can just do: let myObject =