I have just updated my Swift 2 project to Swift 3 and I'm having a problem with a query on the AddressBook:
import Cocoa
import AddressBook
let firstName:String = "John"
let lastName:String = "Appleseed"
let addressBook = ABAddressBook.shared()
let firstNameSearch = ABPerson.searchElement(forProperty: kABFirstNameProperty,
label: nil,
key: nil,
value: firstName,
comparison: ABSearchComparison(kABEqualCaseInsensitive.rawValue))
let lastNameSearch = ABPerson.searchElement(forProperty: kABLastNameProperty,
label: nil,
key: nil,
value: lastName,
comparison: ABSearchComparison(kABEqualCaseInsensitive.rawValue))
let comparisons = [firstNameSearch, lastNameSearch]
let andComparison = ABSearchElement(forConjunction: CFIndex(kABSearchAnd.rawValue), children: comparisons)
let peopleFound = addressBook?.records(matching: andComparison) as! [ABRecord]
if peopleFound.count > 0
{
let contact = peopleFound[0]
}
It's crashing with this error
2016-09-15 12:59:02.657 com.apple.dt.Xcode.PlaygroundStub-macosx[37940:8204350] -[_SwiftValue searchRecordClasses]: unrecognized selector sent to instance 0x7fc098ec9600 2016-09-15 12:59:02.658 com.apple.dt.Xcode.PlaygroundStub-macosx[37940:8204350] An uncaught exception was raised 2016-09-15 12:59:02.658 com.apple.dt.Xcode.PlaygroundStub-macosx[37940:8204350] -[_SwiftValue searchRecordClasses]: unrecognized selector sent to instance 0x7fc098ec9600
when executing this line:
let andComparison = ABSearchElement(forConjunction: CFIndex(kABSearchAnd.rawValue), children: comparisons)
Does anyone know what the updated Swift 3 code should be?