How do I compare two dictionaries in Swift?
问题 Is there an easy way to compare two [String: AnyObject] dictionaries in swift, since it doesn't accept the == operator? By comparing two dictionaries, I mean checking that they have the same exact keys and for every key they have the same values. 回答1: As already mentioned by Hot Licks you can use NSDictionary method isEqualToDictionary() to check if they are equal as follow: let dic1: [String: AnyObject] = ["key1": 100, "key2": 200] let dic2: [String: AnyObject] = ["key1": 100, "key2": 200]