static NSMutableDictionary * allTheSingletons;
@implementation BGSuperSingleton
+(instancetype)singleton
{
return [self singleton1];
}
+(id) singleton1
{
NSString* className = NSStringFromClass([self class]);
if (!allTheSingletons)
{
allTheSingletons = NSMutableDictionary.dictionary;
}
id result = allTheSingletons[className];
PO(result);
if (result==nil)
{
result = [[[self class] alloc]init];
allTheSingletons[className]=result;
}
return result;
}
BGSuperSingleton は、すべてのシングルトン クラスの親である必要があります。
次に、サブクラスの 1 つで行います。
+(NSPredicate *)withinASquare:(double)distance{
CLLocation * anchorWeUsed=[self singleton].mapCenterLocation; //Error map center is not of type ID
return [self withinASquare:distance fromLocation:anchorWeUsed];
}
CLANG は singleton がタイプであることを理解せず+(instancetype)
、代わりにタイプが id であると考えているようです。
私は何が欠けていますか?
self
ただし、MySubSingletonClass
(コンパイル時に既知のものである)に置き換えることは機能します。
説明はありますか?