kCFCompareEqualTo在swift中不可用吗?

时间:2014-08-25 07:59:41

标签: ios swift abrecordref

我正在尝试获取联系人列表中的某个人的电话号码,并且我遇到了比较两个CFS字符串的问题,因为我似乎没有找到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   {

}

2 个答案:

答案 0 :(得分:1)

试试这个:

if ( CFStringCompare(currentPhoneLabel, kABPersonPhoneMobileLabel, 0) == CFComparisonResult.CompareEqualTo)  {

}

希望这会有所帮助.. :)

答案 1 :(得分:1)

正确实施是:

if (CFStringCompare(mediaType as CFString, kUTTypeImage, .CompareCaseInsensitive) == CFComparisonResult.CompareEqualTo ){

}