ios - Filter two arrays Swift -
i have 1 empty array , 2 arrays data
var resultsarray = [string]() var array1 = ["1","2","2","3","4"] var array2 = ["1","2","2","3","4","5","6"]
my goal append resultsarray
elements array2
don't match array1
("5" , "6" in example).
what's subtlest way so?
thank you.
use filter
function
var resultsarray = [string]() let array1 = ["1","2","2","3","4"] let array2 = ["1","2","2","3","4","5","6"] let filteredarray = array2.filter{ !array1.contains($0) } resultsarray.appendcontentsof(filteredarray)
if collections contain unique items consider use set
rather array
Comments
Post a Comment