加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ios – 在Xcode中修复“Lexical或Preprocessor Issue – Extensi

发布时间:2020-12-14 17:42:58 所属栏目:百科 来源:网络整理
导读:我继承了一个新项目,该项目有多个保留周期警告,这些警告是通过在各个块中隐式保留self来实现的. 在尝试解决这些问题时,我写了 __weak typeof(self) weakSelf = self; 创建一个弱的引用以便在块中使用. 但是,Xcode v.5.1.1给出了神秘的警告 Lexical or Prepro
我继承了一个新项目,该项目有多个保留周期警告,这些警告是通过在各个块中隐式保留self来实现的.

在尝试解决这些问题时,我写了

__weak typeof(self) weakSelf = self;

创建一个弱的引用以便在块中使用.

但是,Xcode v.5.1.1给出了神秘的警告

Lexical or Preprocessor Issue 
Extension used

我在这里不知所措 – 这是什么意思,我怎么能摆脱它?

解决方法

如果在构建设置中启用了“Pedantic Warnings”,则会出现使用typeof的警告.
从此设置的“快速帮助”:

Description Issue all the warnings demanded by strict ISO C and ISO
C++; reject all programs that use forbidden extensions,and some other
programs that do not follow ISO C and ISO C++. For ISO C,follows the
version of the ISO C standard specified by any -std option used.
[GCC_WARN_PEDANTIC,-pedantic]

我不是(ISO)C标准的专家,但根据
https://gcc.gnu.org/onlinedocs/gcc/Typeof.html:

If you are writing a header file that must work when included in ISO C
programs,write __typeof__ instead of typeof. See Alternate Keywords.

和http://clang.llvm.org/docs/UsersManual.html:

The parser recognizes “asm” and “typeof” as keywords in gnu* modes;
the variants “__asm__” and “__typeof__” are recognized in all modes.

你可以改用__typeof__
如果您不想禁用警告:

__weak __typeof__(self) weakSelf = self;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读