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
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?
No, Swift dictionaries are not directly comparable. For the purposes of unit-testing, you can either do manual comparisons of their sizes and pair-wise element comparisons, or you can do the easy thing and create NSDictionary
s out of them and compare them that way.
Try
XCTAssertEqual(swiftDict as NSObject, objCDict as NSObject)
Forces the compiler to just chill out and call the isEqual:
method on both.
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)
}
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