Find whether two Swift Arrays contain the same elements
问题 I have two arrays let a1 = [obj1, obj2, obj3] let a2 = [obj3, obj2, obj1] Assume that the array elements are custom objects which are not sortable . I just want to check if the Array s contain the same elements, in any order. I tried this: if a1==a2 { print("S1 is the same as S2") } else { print("S1 is not the same as S2") } but I get "S1 is not the same as S2" as output. All I could think of are two solutions Sort and compare (doesn't work if elements are not sortable, say complex numbers)