Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift: doesNotContain method for Array

Tags:

ios

swift

I am familiar with the contains(array, object) function, but I am in need of a "does not contain" function. I can't think of any logic to work around it, so I could use some help!

My code currently is the exact opposite of what I need. It is only appending objects that are contained in the array; I want it to append every object that is NOT in array.

Code is here:

var array = ["Ben", "Jessica", "Cody", "Katie", "Jacob"]
if array.contains("Ben") {
    print("Contains Ben")
}
like image 929
bkSwifty Avatar asked Nov 28 '22 23:11

bkSwifty


1 Answers

Feeling dumb.

!contains(array, "Ben")
like image 131
bkSwifty Avatar answered Dec 10 '22 02:12

bkSwifty