The main thing to remember is that "$0" represents each item in the array.
(Swift 2.2)
let array = ["Mark", "Matt", "Matthew", "Bob"]
let filtered = array.filter({$0.containsString("Matt")})
print(filtered.count)
class Person {
var name: String!
var age: Int!
init(_ name: String, _ age: Int) {
self.name = name
self.age = age
}
}
var people = [Person]()
people.append(Person("Mark", 45))
people.append(Person("Matt", 46))
people.append(Person("Julie", 50))
people.append(Person("Patty", 51))
people.append(Person("Bob", 52))
let filteredPeople = people.filter({$0.age >= 50})
print(filteredPeople.count)
(Swift 2.2)
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.