I was trying to do something in Swift that would be easy in Objective-C using KVC. The new Contacts framework added in iOS9 is for the most part easier to use than the old Addr
If you are looking for a more Swift-y way to do it:
let matches = contacts.filter {
return $0.phoneNumbers
.flatMap { $0.value as? CNPhoneNumber }
.contains { $0.stringValue == JennysPhone }
}
.flatMap
casts each member of phoneNumbers
from type CNLabeledValue
to type CNPhoneNumber
, ignoring those that cannot be casted.
.contains
checks if any of these phone numbers matches Jenny's number.