When I was writing a compatibility wrapper for AddressBook and Contacts frameworks, I found this code does not work in iOS 7:
import Foundation
import AddressBook
import AddressBookUI
import Contacts
import ContactsUI
private var k2Key: [ABPropertyID: String] = [
://...
]
private func setupConstants() {
//...
if #available(iOS 8.0, *) {
// Alternate birthday
//@availability(iOS, introduced=8.0)
k2Key[kABPersonAlternateBirthdayProperty] = MyContactNonGregorianBirthdayKey
}
//...
}
As shown in the comment, the constant kABPersonAlternateBirthdayProperty is introduced in iOS 8.0, so I enclosed the code with #available check.
But it causes a runtime error, when run on iOS 7 device:
dyld: Symbol not found: _kABPersonAlternateBirthdayProperty
Referenced from: /var/mobile/Applications/3F5FB593-AC7B-4F5A-9563-66A5949769D4/QuickContacts.app/QuickContacts
Expected in: /System/Library/Frameworks/AddressBook.framework/AddressBook
in /var/mobile/Applications/3F5FB593-AC7B-4F5A-9563-66A5949769D4/QuickContacts.app/QuickContacts
How do you check availability of a constant and use it safely?