I'm using Swift to extract data from the AddressBook. Everything works fine if I build the app using Debug. But if I build the app using a release configuration, it crashing in this function:
private func extractProperty<T>(record:ABRecord, propertyName : ABPropertyID) -> T? {
return ABRecordCopyValue(record, propertyName)?.takeRetainedValue() as? T
}
After some testing, I found that it was crashing when I tried to retrieve a "middleName" that the contact didn't have. I split the chain out to figure out where exactly it was crashing and it turns out to be crashing in takeRetainedValue()
. So even though ABRecordCopyValue
isn't returning a value, Swift still thinks it is and passes it along the optional chain. I've tried various means of testing for nil
but nothing seems to work.
This is only occurring in the release build, though. Not the debug build.
Any ideas on how to fix this?