Cannot find overload for XCTAssertEqual that takes a list of arguments of type ([String: AnyObject], [String: AnyObject])

I have one method:

func tableAsDictionary() -> [String: AnyObject] 

Then I need to check this:

 let tableDictionary = table.tableAsDictionary() let expectedDictionary: [String: AnyObject] = [ "id": "1234", "name": "Next to window", "number": 23 ] XCTAssertEqual(tableDictionary, expectedDictionary) //error 

Cannot find an overload for XCTAssertEqual that takes a list of arguments like [String : AnyObject], [String : AnyObject]

+5
source share
1 answer

The problem is that the == operator for dictionaries requires that both the key and the Equatable value Equatable :

 func ==<Key : Equatable, Value : Equatable>(lhs: [Key : Value], rhs: [Key : Value]) -> Bool 

but AnyObject does not match Equatable .

A simple fix is ​​to replace the dictionary type [String: AnyObject] [String : NSObject] , then your code compiles without problems.

+7
source

All Articles