ios – 在Xcode中修复“Lexical或Preprocessor Issue – Extension used”警告?

前端之家收集整理的这篇文章主要介绍了ios – 在Xcode中修复“Lexical或Preprocessor Issue – Extension used”警告?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我继承了一个新项目,该项目有多个保留周期警告,这些警告是通过在各个块中隐式保留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;

猜你在找的Xcode相关文章