我在 Xcode 6.4 中打开了两个项目。两者都使用以下声明:
- (void)startService
{
__weak typeof(self) weakSelf = self;
[self.messageOperationQueue addOperationWithBlock:^{
NSDictionary *storedMessages = [mySettings get:kStorageName withDefault:@{} storageType:kMySettingsStorageTypeDiskMapped];
[weakSelf.messages addEntriesFromDictionary:storedMessages];
}];
}
然而,在一个项目中没有任何错误,而在另一个项目中出现编译错误:
Expected ';' at end of declaration
它要我在 __weak typeof(self) 后面放一个分号。我怀疑我只是在做一些非常愚蠢的事情,但我无法弄清楚是什么。另外,我知道我可以将 typeof(self)
替换为 myClass *
。
最佳答案
使用 __typeof
而不是 typeof
。
这是因为 __typeof
和 typeof
都是对 C 的扩展,但是 typeof
只有在语言为 时才在 Clang 中启用>GNUXX
C 的变体,但不适用于 CXX
。
关于objective-c - 预期为 "__weak typeof(self) weakSelf = self;";在声明结束时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32145326/