objective-c - 预期为 "__weak typeof(self) weakSelf = self;";在声明结束时

标签 objective-c

我在 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

这是因为 __typeoftypeof 都是对 C 的扩展,但是 typeof 只有在语言为 时才在 Clang 中启用>GNUXX C 的变体,但不适用于 CXX

关于objective-c - 预期为 "__weak typeof(self) weakSelf = self;";在声明结束时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32145326/

相关文章:

ios - NSURLSession,重试加载数据

ios - "unrecognized selector sent to instance"performSegueWithIdentifier 错误,使用 SWRevealViewController

iPhone SDK - 将我的基于委托(delegate)的函数转换为 block

objective-c - 如何将此 Perl Skript (Sipgate API) 转换为 Objective C/Cocoa?

objective-c - 必须调用父类(super class) 'UITableViewController' 的指定初始值设定项

ios - indexPathForCell : returning nil

ios - 线程 1 : Signal SIGABRT due to calling another method

objective-c - 如何在 iPhone 上镜像视频?

ios - 在 ios 7 中关闭 UIAlertView 不起作用?

ios - NSURLConnection 的 SynchronousRequest 的 DidReceiveAuthenticationChallenge