How to compare two nested Dictionaries for equality?

There are multiple issues with your code, but the main problem is, you can't establish equality of two arbitrary [AnyHashable:Any] dictionaries. You can write such a test for something like [AnyHashable:AnyEquatable]. You can write or use an existing AnyEquatable type eraser, or you may be able to go with [AnyHashable: AnyHashable] if your values are all going to be Hashable.

For correct type casting see this thread: How to capture a type then cast to it

1 Like