2

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?

Aaron Hayman
  • 8,492
  • 2
  • 36
  • 63
  • For those who will be wondering how to call the function above (like me in a month), use something like this: `var firstname = extractProperty(person, propertyName: kABPersonFirstNameProperty) as String?` – Maksim May 19 '15 at 08:48

1 Answers1

1

So I decided to try building this under Swift 1.2 (Xcode 6.3) and it works (after spending about an hour converting the project). So it was definitely a compiler error that has been fixed in the latest Swift.

Aaron Hayman
  • 8,492
  • 2
  • 36
  • 63