When you have optionals and code completion suggests testing for '!= nil', you must keep in mind true and false are both not nil. In this scenario it's best to do something like this:
if let bool = data?.contains("string") { boolVariable = bool }