我可以在自己的类(文件)中看到单例的属性,但我无法在调试器的其他文件中看到它们。由于singleton充当全局变量,为什么我不能或如何在调试器上看到它?我是否必须将单例分配给另一个局部变量,以便我可以观察局部变量而不是单例?
答案 0 :(得分:0)
通常你有一个sharedInstance
类方法
@implementation MySingleton
+ (MySingleton *)sharedInstance {
static MySingleton *_sharedInstance = nil;
static dispatch_once_t once_token = 0;
dispatch_once(&once_token, ^{
_sharedInstance = [[MySingleton alloc] init];
});
return _sharedInstance;
}
@end
并通过
访问它MySingleton *mySingleton = [MySingleton sharedInstance];