Xcode 9抛出涉及’require’的错误

前端之家收集整理的这篇文章主要介绍了Xcode 9抛出涉及’require’的错误前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
升级代码以在 Xcode 9下构建时,我在使用require和require_noerr的代码中看到了编译错误
require(length > offsetof(struct blob,cert),outLabel);

第一个错误是:
错误:C99中函数’require’的隐式声明无效

我也遇到了很多错误:使用未声明的标识符’outLabel’.这是在RRTransactionVerifier.m中,这是用于处理收据验证的Apple代码.

我该如何解决这些错误

解决方法

require和require_noerr是以前在AssertMacros.h中定义的宏.从Xcode 9开始,这些宏发生了变化.

原因记录在该头文件中:

For time immemorial,Mac OS X has defined version of most of these
macros without the __ prefix,which could collide with similarly named
functions or macros in user code,including new functionality in Boost
and the C++ standard library.

macOS High Sierra and iOS 11 will now require that clients move to the
new macros as defined above.

If you would like to enable the macros for use within your own
project,you can define the
__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERscoreS macro via an Xcode Build Configuration. See “Add a build configuration (xcconfig) file”
in Xcode Help.

因此,要解决此问题,您可以设置定义或更改代码以使用新宏.
require现在是__Require,require_noerr现在是__Require_noErr,依此类推.它们在头文件中提供了有关如何通过脚本更改代码的脚本:

编辑:在脚本的第一行末尾添加一个反斜杠,否则终端会将命令分成两个.

/*
To aid users of these macros in converting their sources,the following tops script 
will convert usages of the old macros into the new equivalents.  To do so,in Terminal 
go into the directory containing the sources to be converted and run this command.

find . -name '*.[c|cc|cp|cpp|m|mm|h]' -print0 |  xargs -0 tops \
-verbose \
      replace "check(<b args>)" with "__Check(<args>)" \
      replace "check_noerr(<b args>)" with "__Check_noErr(<args>)" \
      replace "check_noerr_string(<b args>)" with "__Check_noErr_String(<args>)" \
      replace "check_string(<b args>)" with "__Check_String(<args>)" \
      replace "require(<b args>)" with "__Require(<args>)" \
      replace "require_action(<b args>)" with "__Require_Action(<args>)" \
      replace "require_action_string(<b args>)" with "__Require_Action_String(<args>)" \
      replace "require_noerr(<b args>)" with "__Require_noErr(<args>)" \
      replace "require_noerr_action(<b args>)" with "__Require_noErr_Action(<args>)" \
      replace "require_noerr_action_string(<b args>)" with "__Require_noErr_Action_String(<args>)" \
      replace "require_noerr_string(<b args>)" with "__Require_noErr_String(<args>)" \
      replace "require_string(<b args>)" with "__Require_String(<args>)" \
      replace "verify(<b args>)" with "__Verify(<args>)" \
      replace "verify_action(<b args>)" with "__Verify_Action(<args>)" \
      replace "verify_noerr(<b args>)" with "__Verify_noErr(<args>)" \
      replace "verify_noerr_action(<b args>)" with "__Verify_noErr_Action(<args>)" \
      replace "verify_noerr_string(<b args>)" with "__Verify_noErr_String(<args>)" \
      replace "verify_string(<b args>)" with "__Verify_String(<args>)" \
      replace "ncheck(<b args>)" with "__nCheck(<args>)" \
      replace "ncheck_string(<b args>)" with "__nCheck_String(<args>)" \
      replace "nrequire(<b args>)" with "__nRequire(<args>)" \
      replace "nrequire_action(<b args>)" with "__nRequire_Action(<args>)" \
      replace "nrequire_action_quiet(<b args>)" with "__nRequire_Action_Quiet(<args>)" \
      replace "nrequire_action_string(<b args>)" with "__nRequire_Action_String(<args>)" \
      replace "nrequire_quiet(<b args>)" with "__nRequire_Quiet(<args>)" \
      replace "nrequire_string(<b args>)" with "__nRequire_String(<args>)" \
      replace "nverify(<b args>)" with "__nVerify(<args>)" \
      replace "nverify_string(<b args>)" with "__nVerify_String(<args>)" \
      replace "require_action_quiet(<b args>)" with "__Require_Action_Quiet(<args>)" \
      replace "require_noerr_action_quiet(<b args>)" with "__Require_noErr_Action_Quiet(<args>)" \
      replace "require_noerr_quiet(<b args>)" with "__Require_noErr_Quiet(<args>)" \
      replace "require_quiet(<b args>)" with "__Require_Quiet(<args>)" \
      replace "check_compile_time(<b args>)" with "__Check_Compile_Time(<args>)" \
      replace "debug_string(<b args>)" with "__Debug_String(<args>)"
*/
原文链接:https://www.f2er.com/iOS/335621.html

猜你在找的iOS相关文章