3

I search in Stack, but I don't find my answer.
I have two arrays and I want to get different elements of them.

ex:

var a:[String] = ["a","b","c"]
var b:[String] = ["a","b","d"]
//a compare with b and get ["c","d"] 


var c:[String] = ["a","b","c","d"]
var d:[String] = ["a","b","c"]   
//c compare with d and get ["d"]

Sorry I'm beginner of swift.
And how to do this idea?
Thanks.

JimmyLee
  • 507
  • 2
  • 7
  • 24

1 Answers1

9

Try symmetricDifference:

// ["d"]
Set(["a", "b", "c"]).symmetricDifference(["a", "b", "c", "d"])

Returns a new set with the elements that are either in this set or in the given sequence, but not in both.

Sweeper
  • 213,210
  • 22
  • 193
  • 313