最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

[已解决]swift代码警告: Logical not is only applied to the left hand side of this comparison

iOS crifan 5482浏览 0评论

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 (!)

Fails to build with GCC 5.0: logical not is only applied to the left hand side of comparison · Issue #39 · dsully/perl-crypt-openssl-x509

Error compiling: logical not is only applied to the left hand side of comparison [-Werror=logical-not-parentheses] | JModelica.org

通过看完整代码,感觉逻辑应该是:

针对于:

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

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
84 queries in 0.168 seconds, using 22.05MB memory