无法调用' =='使用类型'($ T2,OSStatus)'的参数列表在Xcode 6.1中

时间:2014-10-25 22:11:07

标签: xcode swift

当我使用Xcode版本6时,我用于访问Keychain的类正在运行,但现在在版本6.1中它无法正常工作

以下是Keychain访问类的一部分:

class func setData(value: NSData, forKey keyName: String) -> Bool {
    var keychainQueryDictionary: NSMutableDictionary = self.setupKeychainQueryDictionaryForKey(keyName)

    keychainQueryDictionary[kSecValueData as String] = value

    // Protect the keychain entry so it's only valid when the device is unlocked
    keychainQueryDictionary[kSecAttrAccessible as String] = kSecAttrAccessibleWhenUnlocked

    let status: OSStatus = SecItemAdd(keychainQueryDictionary, nil)

    if Int(status) == errSecSuccess { //I GET THE ERROR HERE
        return true
    } else if Int(status) == errSecDuplicateItem {
        return self.updateData(value, forKey: keyName)
    } else {
        return false
    }
}

这不是它在这里做的唯一地方是代码的另一部分:

class func removeObjectForKey(keyName: String) -> Bool {
     let keychainQueryDictionary: NSMutableDictionary = self.setupKeychainQueryDictionaryForKey(keyName)

    //Delete
    let status: OSStatus =  SecItemDelete(keychainQueryDictionary);

    if Int(status) == errSecSuccess { //GET ERROR HERE
        return true
    } else {
        return false
    }
}

看起来像问题是errSecSuccess可以有人帮助我

1 个答案:

答案 0 :(得分:3)

OSStatusInt32的别名,因此我认为您可以通过删除转化为Int来解决此问题,例如:

if status == errSecSuccess {

附注:您的多个if/elseif/else可以替换为switch

switch (status) {
case errSecSuccess:
    ...

case errSecDuplicateItem:
    ...

default:
    ...
}
在我看来,

更具可读性