我正在尝试在联系人列表中获取某人的电话号码,并且在尝试比较两个CFString时遇到问题,因为我似乎无法迅速找到kCFCompareEqualTo属性
在ObjectiveC中,您可以执行以下操作:
ABMultiValueRef phonesRef = ABRecordCopyValue(person, kABPersonPhoneProperty);
for (int i=0; i < ABMultiValueGetCount(phonesRef); i++) {
CFStringRef currentPhoneLabel = ABMultiValueCopyLabelAtIndex(phonesRef, i);
CFStringRef currentPhoneValue = ABMultiValueCopyValueAtIndex(phonesRef, i);
if (CFStringCompare(currentPhoneLabel, kABPersonPhoneMobileLabel, 0) == kCFCompareEqualTo) {
[contactInfoDict setObject:(__bridge NSString *)currentPhoneValue forKey:@"mobileNumber"];
}
我尝试过这样的事情:
var phoneRef :ABMultiValueRef = ABRecordCopyValue(person, kABPersonPhoneProperty).takeRetainedValue()
var i = 0
for i ; i < ABMultiValueGetCount(phoneRef) ; i++ {
var currentPhoneLabel : CFString = ABMultiValueCopyLabelAtIndex(phoneRef, i).takeRetainedValue()
var currentPhoneValue : CFString = ABMultiValueCopyValueAtIndex(phoneRef, i).takeRetainedValue() as CFString
if ( CFStringCompare(currentPhoneLabel, kABPersonPhoneMobileLabel, 0) == ???) {
}
}
你能告诉我如何解决这个问题吗?
编辑:
我尝试了这个,现在它并没有失败
var smth = CFStringCompare(currentPhoneLabel, kABPersonPhoneMobileLabel,CFStringCompareFlags.CompareCaseInsensitive) as CFComparisonResult
if smth == CFComparisonResult.CompareEqualTo {
}
最佳答案
尝试这个:
if ( CFStringCompare(currentPhoneLabel, kABPersonPhoneMobileLabel, 0) == CFComparisonResult.CompareEqualTo) {
}
希望这可以帮助.. :)
关于ios - kCFCompareEqualTo不能立即使用吗?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25481459/