In Objective-C you can easily initialize NSSet objects that contains NSArray objects as elements. And you can easily compare those NSSet objects thanks to the isEqual: method.
Now in Swift, which is much more strongly typed, we can no longer do this. The following declaration will receive a "Type [Int] does not conform to protocol Hashable" error.
var set: Set<[Int]>
I am now trying to compare the equality of two groups of arrays that contain a bunch of Int numbers, I want to take advantage of the "isEqual:" idea with Set and Array in Swift, What should I do?
Hashable, but as this requires avar hashValue, it cannot be defined in another module, sadly. – vrwim May 10 '15 at 12:02hashValuecan be a computed property as well, which can be added in extensions without issues. – DeFrenZ May 12 '15 at 10:35hashValueneeds to be declaredpublic, which cannot be added in extensions. – vrwim May 13 '15 at 8:31extension NSArray: Equatable {} public func ==(lhs: NSArray, rhs: NSArray) -> Bool { return lhs.isEqualToArray(rhs as [AnyObject]) } extension NSArray: Hashable { var hashable: Int { return 1 } } let fooSet: Set<NSArray> = [NSArray(array: [1, 2])] fooSet.dynamicTypeThis compiles on my playground (sorry can't format long code in comments?) – DeFrenZ May 13 '15 at 9:59