Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot find an overload for XCTAssertEqual that accepts an argument list of type ([String : AnyObject], [String : AnyObject])

Tags:

swift

xctest

I have one method:

func tableAsDictionary() -> [String: AnyObject]

Then I need to test 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 accepts an argument list of type [String : AnyObject], [String : AnyObject]

like image 623
Bartłomiej Semańczyk Avatar asked Jul 28 '15 08:07

Bartłomiej Semańczyk


1 Answers

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

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

but AnyObject does not conform to Equatable.

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

like image 76
Martin R Avatar answered Nov 14 '22 23:11

Martin R