Skip to content

Instantly share code, notes, and snippets.

@tkausch
Last active September 18, 2020 16:41
Show Gist options
  • Save tkausch/b22f9d67171584137bffbea30521d36a to your computer and use it in GitHub Desktop.
Save tkausch/b22f9d67171584137bffbea30521d36a to your computer and use it in GitHub Desktop.
How to check whether a string contains any words from an array
// Remember you can check wether a string contains a single word
let sentence = "I'was eating pommes with chees and an Apple for desert."
print(sentence.contains("Apple"))
// ... and we can also check if an array contains a word
let words = ["Apple", "Banana", "Orange"]
print(words.contains("Apple"))
// We can combine together do any of the words fulfill where clause?
print(words.contains(where: sentence.contains))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment