Swift: didNotContain method for array
I'm familiar with the function contains(array, object)
, but I need a "does not contain" function. I can't think of any logic to get around this, so I could use some help!
My code is currently the exact opposite of what I need. This is only adding objects that are contained in array
; I want to add every object that is not in array
.
The code is here:
var array = ["Ben", "Jessica", "Cody", "Katie", "Jacob"]
if array.contains("Ben") {
print("Contains Ben")
}
+3
source to share
3 answers