I am filtering a CNContact
phoneNumbers
to see if dialed number is contained within the contact's
number. Bellow attached code works fine, but.....
My problem: If the phone number has no white spaces inside, works ok but if I search "0761" and contact's phone number is "076 1", it ignores it.
I am using NSPredicate
. Code:
func filterAndGetCurrentPhoneNumber(c: CNContact) -> String{
let searchPredicate = NSPredicate(format: "SELF.value.stringValue CONTAINS[c] %@", self.txtf_dial.text!)
let array = (c.phoneNumbers as NSArray).filteredArrayUsingPredicate(searchPredicate)
if array.count > 0{
let str: String? = ((array[0] as! CNLabeledValue).value as! CNPhoneNumber).stringValue
if str != nil {
return str!;
}
}
return ""
}
How can I modify NSPredicate
to ignore whitespaces in swift?