【问题标题】:iOS Objective-C: weakSelf SyntaxiOS Objective-C:weakSelf 语法
【发布时间】:2015-03-31 00:08:25
【问题描述】:

我在网上遇到的几乎每个weakSelf 模式的例子都有语法

__weak typeof(self) weakSelf = self;

但是编译器在最新版本的 Xcode 中抱怨这种语法,要求:

__weak __typeof__(self) weakSelf = self;

语法改变了,还是我错过了导入?我尝试拉入<objc/runtime.h>,但没有任何变化。

隐秘的奖励问题:为什么不直接施放呢?

__weak MyBoffoClass *weakSelf = self;

我在这里找到了一个答案,说最好直接投射它,但没有理由说明为什么。

【问题讨论】:

标签: ios objective-c design-patterns automatic-ref-counting weak-references


【解决方案1】:

在@danh 的帮助下将我指向Difference between typeof, __typeof and __typeof__ (Objective-c),我发现问题出在编译器设置中。

点击Project Navigator窗口顶部的项目,点击Build Settings,选择View All:

接下来向下滚动到 Apple LLVM n。n - 语言并检查设置:

在我的例子中,语言方言设置为 C99,它不支持 GNU 编译器宏和 C 语言的其他扩展。

不知道为什么项目会这样设置(项目架构师不记得为什么),我只需要在阅读 StackOverflow 代码 sn-ps 时考虑到这一事实。比通过更改来引入一些东西要好,因为我是一个懒惰的打字员。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-13
    • 2012-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多