我在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) 后面放一个分号。我怀疑我可能只是做了一些非常愚蠢的事情,但我很难弄清楚具体是什么。此外,我知道我可以用 myClass *
替换 typeof(self)
。
__block
而不是__weak
。 - musical_coder__typeof
起作用了。为什么? - Ben Flynn__weak __typeof(self) weakSelf = self;
看起来很丑。 - Léo Natan