iOS的swift代码:
if (! SecItemCopyMatching((CFDictionaryRef)tempQuery, (void *)&outDictionary) == noErr)
完整代码是:
//if (! SecItemCopyMatching((CFDictionaryRef)tempQuery, (CFTypeRef *)&outDictionary) == noErr)
//if (! SecItemCopyMatching((CFDictionaryRef)tempQuery, (void *)&outDictionary) == noErr)
if (! SecItemCopyMatching((CFDictionaryRef)tempQuery, (void *)&outDictionary) == noErr)
{
// Stick these default values into keychain item if nothing found.
[self resetKeychainItem];
// Add the generic attribute and the keychain access group.
[keychainItemData setObject:identifier forKey:(id)kSecAttrGeneric];
if (accessGroup != nil)
{
#if TARGET_IPHONE_SIMULATOR
// Ignore the access group if running on the iPhone simulator.
//
// Apps that are built for the simulator aren’t signed, so there’s no keychain access group
// for the simulator to check. This means that all apps can see all keychain items when run
// on the simulator.
//
// If a SecItem contains an access group attribute, SecItemAdd and SecItemUpdate on the
// simulator will return -25243 (errSecNoAccessForItem).
#else
[keychainItemData setObject:accessGroup forKey:(id)kSecAttrAccessGroup];
#endif
}
}
else
{
// load the saved data from Keychain.
self.keychainItemData = [self secItemFormatToDictionary:outDictionary];
}
出现警告:
KeychainItemWrapper/KeychainItemWrapper.m:134:13: Logical not is only applied to the left hand side of this comparison
如图:
c++ – warning: Wlogical-not-parentheses – Stack Overflow
61271 – 10 * possible coding error with logical not (!)
通过看完整代码,感觉逻辑应该是:
针对于:
SecItemCopyMatching((CFDictionaryRef)tempQuery, (void *)&outDictionary) == noErr
去取反的
所以,感觉应该使用建议:
Add parentheses after the ‘!’ to evaluate the comparison first
而不是:
Add parentheses around left hand side expression to silence this warning
即:
【总结】
改为:
if (! (SecItemCopyMatching((CFDictionaryRef)tempQuery, (void *)&outDictionary) == noErr))
即可。
转载请注明:在路上 » [已解决]swift代码警告: Logical not is only applied to the left hand side of this comparison