在尝试解决这些问题时,我写了
__weak typeof(self) weakSelf = self;
创建一个弱的引用以便在块中使用.
但是,Xcode v.5.1.1给出了神秘的警告
Lexical or Preprocessor Issue Extension used
我在这里不知所措 – 这是什么意思,我怎么能摆脱它?
解决方法
从此设置的“快速帮助”:
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 oftypeof
. 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;