title: Find whether two Swift Arrays contain the same elements
body: <p>I have two arrays</p>
  
  <pre><code>let a1 = [obj1, obj2, obj3]
  let a2 = [obj3, obj2, obj1]
  </code></pre>
  
  <p>Assume that the array elements are custom objects which are <strong>not sortable</strong>. I just want to check if the <code>Array</code>s contain the same elements, in any order.</p>
  
  <p>I tried this: </p>
  
  <pre><code>if a1==a2 { print("S1 is the same as S2") }
  else { print("S1 is not the same as S2") }
  </code></pre>
  
  <p>but I get "S1 is not the same as S2" as output.</p>
  
  <p>All I could think of are two solutions</p>
  
  <ul>
  <li>Sort and compare (doesn't work if elements are not sortable, say complex numbers)</li>
  <li>Subtract one array from the other</li>
  </ul>
  
  <p>Is there any built-in function or operation to check if they are equal, without considering order?</p>
  
  <p>I found <a href="https://stackoverflow.com/questions/36714522/how-do-i-check-in-swift-if-two-arrays-contain-the-same-elements-regardless-of-th">How do I check in Swift if two arrays contain the same elements regardless of the order in which those elements appear in?</a> which has the answer only for <strong>sortable</strong> <code>Array</code>s.</p>