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]
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With