ios - kCFCompareEqualTo 在 swift 中不可用吗?

标签 ios swift abrecordref

我正在尝试获取联系人列表中某个人的电话号码,但在比较两个 CFString 时遇到问题,因为我似乎没有在 swift 中找到可用的 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 在 swift 中不可用吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25481459/

相关文章:

ios - 如何更改 UIImage 的颜色

ios - 从 xib 实例化自定义表格 View 单元格失败

swift - 遍历每个节点名称

swift - 在 Swift 中使用另一个变量的初始化值初始化变量

multithreading - iPhone : address book is erased sometimes

ios - 是否可以在故​​事板中将 CollectionViewFlowLayout 更改为 CollectionViewLayout

ios - 将数据从 UIViewController1 传递到 UIViewController2 时 UIViewController2 的背景颜色消失

ios - 应用内购买恢复功能

iphone - 设置人员属性

ios - 从 Unmanaged<AnyObject> 获取 swift 类型的值。例如 : ABRecordRef