title: getting unique items in an array
body: <p>I have an array which has repeated items, i want to get unique items only so i did this:</p>
  <pre><code>    let decoded  = userDefaults.object(forKey: &quot;shifts&quot;) as! Data
      myShifts = NSKeyedUnarchiver.unarchiveObject(with: decoded) as! [Shift]
      filtered_shifts = myShifts.filter{$0.regionName == region &amp;&amp; $0.cityName == city &amp;&amp; $0.idService == idservice &amp;&amp; $0.quantityStaff != 0}
      for shift in filtered_shifts {
          let decoded4  = userDefaults.object(forKey: &quot;nationalities&quot;) as! Data
          let decodedNationalities = NSKeyedUnarchiver.unarchiveObject(with: decoded4) as! [Nationality]
          for nationality in decodedNationalities {
              if nationality.id == shift.idNationality{
                  nationalitiesid.append(nationality.id)
                  nationalities.append(nationality.name)
              }
          }
      }
      uniqueNationality = Array(Set(nationalities))
      uniqueNationalityid = Array(Set(nationalitiesid))
  </code></pre>
  <p>which is getting me a new array with unique items as i need...</p>
  <p>the problem is that the order is diferent when i want the same order ... for exampple:</p>
  <blockquote>
  <p>nationalitiesid = [3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4]</p>
  <p>nationalities = [&quot;Indian&quot;, &quot;Indian&quot;, &quot;Indian&quot;, &quot;Indian&quot;, &quot;Indian&quot;, &quot;Indian&quot;, &quot;Indian&quot;, &quot;Indian&quot;, &quot;Philippines&quot;, &quot;Philippines&quot;, &quot;Philippines&quot;, &quot;Philippines&quot;]</p>
  </blockquote>
  <p>the unique array is:</p>
  <blockquote>
  <p>uniqueNationality = [&quot;Indian&quot;, &quot;Philippines&quot;]</p>
  <p>uniqueNationalityid = [4, 3]</p>
  </blockquote>
  <p>and this is wrong since Indian id is 3 and Philippines id is 4!</p>
  <p>it should be:</p>
  <blockquote>
  <p>uniqueNationalityid = [3, 4]</p>
  </blockquote>
  <p>How to solve this?</p>