"__weak typeof(self) weakSelf = self;"预期的 ;在声明结束时 [英] "__weak typeof(self) weakSelf = self;" expected ; at end of declaration

查看:75
本文介绍了"__weak typeof(self) weakSelf = self;"预期的 ;在声明结束时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Xcode 6.4 中打开了两个项目.两者都使用以下声明:

I have two projects open in Xcode 6.4. Both use the follow declaration:

- (void)startService
{
    __weak typeof(self) weakSelf = self;
    [self.messageOperationQueue addOperationWithBlock:^{
        NSDictionary *storedMessages = [mySettings get:kStorageName withDefault:@{} storageType:kMySettingsStorageTypeDiskMapped];
        [weakSelf.messages addEntriesFromDictionary:storedMessages];
    }];
}

然而,在一个项目中没有错误,而在另一个项目中我得到一个编译器错误:

However, in one project there are no errors, and in the other project I get a compiler error:

Expected ';' at end of declaration

它要我在 __weak typeof(self) 后面加一个分号.我怀疑我只是在做一些非常愚蠢的事情,但我无法弄清楚是什么.另外,我知道我可以用 myClass * 替换 typeof(self).

It wants me to put a semi-colon after __weak typeof(self). I have suspicion that I'm just doing something really dumb, but I'm having trouble figuring out what. Also, I know I could replace the typeof(self) with myClass *.

推荐答案

使用 __typeof 而不是 typeof.

这是因为 __typeoftypeof 都是 C 的扩展,但是 typeof 只有在语言是 GNUXX C 的变体,但不适用于 CXX.

This is because both __typeof and typeof are extensions to C, but typeof is only enabled in Clang when the language is a GNUXX variant of C, but not for CXX.

这篇关于"__weak typeof(self) weakSelf = self;"预期的 ;在声明结束时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆