Johan Johan - 2 months ago 7
Objective-C Question

XCTAssertEquals with two dicts in Swift

I am doing the exercism.io programming exercises and the tests I have to perform on my code has the goal to compare to dicts with each other. The sourcecode of the exercise can be found here https://github.com/exercism/xswift/tree/master/word-count

Test code for comparing two dicts

As of what I have understood bridgeToObjectiveC is apples internal methods for doing things and therefore they have been removed. With them i get

'[S : T]' does not have a member named 'bridgeToObjectiveC'
which is very understandable if they have removed it.

Without the method using only the params in the AssertEquals call i get
'[S : T]' does not conform to protocol 'Equatable'
. Is two dicts not comparable in Swift? How would I do to get them comparable?

Answer

You can check equality of dictionaries as long as the values are Equatable. Modify XCTAssertEqualDictionaries to include a generic constraint:

func XCTAssertEqualDictionaries<S, T: Equatable>(first: [S:T], _ second: [S:T]) {
    XCTAssert(first == second)
}