"Binary operator '<' cannot be applied to two CFIndex operands" - 从 ABMultiValue(地址簿)中选择一个 phone 号码
"Binary operator '<' cannot be applied to two CFIndex operands" - choosing a phone number from ABMultiValue (Address Book)
我正在尝试使用 AddressBook 和 AddressBookUI 来显示地址簿的视图,然后用户可以在其中点击联系人,然后点击 phone 号码,应用会收到 phone 号。当我遍历 ABMultiValue 以查找具有所选标识符的条目时遇到问题 - 在 for
循环(第 13 行)的行上引发错误“Binary operator '<' cannot be applied to two CFIndex operands
”。
我粘贴了下面的代码 - 有没有人知道为什么会发生这种情况/我可以做些什么来解决它?谢谢!
func peoplePickerNavigationController(peoplePicker: ABPeoplePickerNavigationController!, didSelectPerson person: ABRecord!, property: ABPropertyID, identifier: ABMultiValueIdentifier) {
self.peoplePickerNavigationController(peoplePicker, shouldContinueAfterSelectingPerson: person, property: property, identifier: identifier)
// Get name
// If wanting a composite name including prefix, suxif, title, both names etc:
// NSString *contactName = CFBridgingRelease(ABRecordCopyCompositeName(person));
let contactName = ABRecordCopyValue(person, kABPersonFirstNameProperty)
// Get number
var number = String()
let numbers = ABRecordCopyValue(person, kABPersonPhoneProperty)
for var index:CFIndex = 0; index < ABMultiValueGetCount(numbers); ++index{
if identifier = ABMultiValueGetIdentifierAtIndex(numbers, index) {
number = ABMultiValueCopyValueAtIndex(numbers, index)
}
}
}
只需使用普通数字循环即可:
for index in 0 ..< ABMultiValueGetCount(numbers) {
我正在尝试使用 AddressBook 和 AddressBookUI 来显示地址簿的视图,然后用户可以在其中点击联系人,然后点击 phone 号码,应用会收到 phone 号。当我遍历 ABMultiValue 以查找具有所选标识符的条目时遇到问题 - 在 for
循环(第 13 行)的行上引发错误“Binary operator '<' cannot be applied to two CFIndex operands
”。
我粘贴了下面的代码 - 有没有人知道为什么会发生这种情况/我可以做些什么来解决它?谢谢!
func peoplePickerNavigationController(peoplePicker: ABPeoplePickerNavigationController!, didSelectPerson person: ABRecord!, property: ABPropertyID, identifier: ABMultiValueIdentifier) {
self.peoplePickerNavigationController(peoplePicker, shouldContinueAfterSelectingPerson: person, property: property, identifier: identifier)
// Get name
// If wanting a composite name including prefix, suxif, title, both names etc:
// NSString *contactName = CFBridgingRelease(ABRecordCopyCompositeName(person));
let contactName = ABRecordCopyValue(person, kABPersonFirstNameProperty)
// Get number
var number = String()
let numbers = ABRecordCopyValue(person, kABPersonPhoneProperty)
for var index:CFIndex = 0; index < ABMultiValueGetCount(numbers); ++index{
if identifier = ABMultiValueGetIdentifierAtIndex(numbers, index) {
number = ABMultiValueCopyValueAtIndex(numbers, index)
}
}
}
只需使用普通数字循环即可:
for index in 0 ..< ABMultiValueGetCount(numbers) {