最新消息:20190717 VPS服务器:Vultr新加坡,WordPress主题:大前端D8,统一介绍入口:关于

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

iOS crifan 1493浏览 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,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
62 queries in 0.116 seconds, using 18.81MB memory