Question : swiftui check if two arrays contain same element
Answered by : tony-sacco
let array1 = [2, 3, 4, 5]
let array2 = [20, 15, 2, 7]
if array1.contains(where: array2.contains) { print("Array 1 and array 2 share at least one common element")
} else { print("Array 1 doesn't contains any elements from array 2")
}
Source : https://stackoverflow.com/questions/37299385/swift-determine-if-array1-contains-at-least-one-object-from-array2 | Last Update : Mon, 05 Dec 22