Created
May 7, 2017 02:14
-
-
Save saoudrizwan/7eadc056c95dc8847af634214341f2ee to your computer and use it in GitHub Desktop.
Quickly check if an array contains a certain element.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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