该项目是非 ARC 启用的,但是我们(错误地)使用了符合 ARC 的代码库 - 特别是一个创建单例对象的代码库,如 GCDSingleton.h 中定义的那样:
#define DEFINE_SHARED_INSTANCE
+ (id)sharedInstance
{
static dispatch_once_t pred = 0;
__strong static id _sharedObject = nil;
dispatch_once(&pred, ^{
_sharedObject = ^{return [[self alloc] init];}();
});
return _sharedObject;
}
Run Code Online (Sandbox Code Playgroud)
即使共享对象是用 __strong 限定符定义的,这似乎也有效。我想知道为什么这不会导致错误或至少是警告(最新的 Xcode 4.6 和 ios 6 sdk)。此外,由于该项目未启用 ARC,那么 __strong 限定符究竟在做什么(如果有的话)?