Skip to content

Instantly share code, notes, and snippets.

@saoudrizwan
Created May 7, 2017 02:14
Show Gist options
  • Save saoudrizwan/7eadc056c95dc8847af634214341f2ee to your computer and use it in GitHub Desktop.
Save saoudrizwan/7eadc056c95dc8847af634214341f2ee to your computer and use it in GitHub Desktop.
Quickly check if an array contains a certain element.
class Person {
let name: String
var age: Int
init(name: String, age: Int) {
self.name = name
self.age = age
}
}
let people = [Person(name: "Saoud", age: 19), Person(name: "Gus", age: 20), Person(name: "Jake", age: 21)]
if people.contains(where: { $0.age == 21 }) {
print("Let's party tonight")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment