More Swifty solution that will stop the search after it finds a nonexistent word:
var text = "Hello Swift-world" var textArray = ["Hello", "world"] let match = textArray.reduce(true) { !$0 ? false : (text.range(of: $1) != nil ) }
Another way to do this, which stops after it finds a mismatch:
let match = textArray.first(where: { !text.contains($0) }) == nil
source share