I have two arrays like this:
var arrayA = ["Mike", "James", "Stacey", "Steve"]
var arrayB = ["Steve", "Gemma", "James", "Lucy"]
As you can see, James
and Steve
match and I want to be able to remove them from arrayA
. How would I write this?
matt and freytag's solutions are the ONLY ones that account for duplicates and should be receiving more +1s than the other answers.
Here is an updated version of matt's answer for Swift 3.0:
For smaller arrays I use:
Using the
Array → Set → Array
method mentioned by Antonio, and with the convenience of an operator, as freytag pointed out, I've been very satisfied using this: