Ios Obj C:无法从调试器访问单例

Ios Obj C:无法从调试器访问单例,ios,objective-c,debugging,singleton,singleton-methods,Ios,Objective C,Debugging,Singleton,Singleton Methods,所以这很奇怪。我刚刚在我的应用程序中创建了一个新的单例,使用了与其他许多单例相同的模式。然而,这个调试器并不好用。以下是获取singleton的代码: - (id)init { self = [super init]; if (self) { [self loadData]; } return self; } + (Settings *)sharedInstance { static Settings *sharedInstance =

所以这很奇怪。我刚刚在我的应用程序中创建了一个新的单例,使用了与其他许多单例相同的模式。然而,这个调试器并不好用。以下是获取singleton的代码:

- (id)init
{
    self = [super init];
    if (self) {
        [self loadData];
    }
    return self;
}

+ (Settings *)sharedInstance
{
    static Settings *sharedInstance = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        sharedInstance = [[self alloc] init];
        // Do any other initialisation stuff here
    });
    return sharedInstance;
}
现在,当我尝试从调试器访问对象时,它会给出以下信息:

error: Execution was interrupted, reason: EXC_BAD_ACCESS (code=1, address=0x20).
The process has been returned to the state before expression evaluation.
显然,我并不是想从调试器中获取单例的句柄,而是想获取一个属性。这提供了一些更有趣的输出:

(lldb) po [Settings sharedInstance].jpegCompressionLevel
error: warning: got name from symbols: Settings
warning: receiver type 'void *' is not 'id' or interface pointer, consider casting it to 'id'
error: no known method '-sharedInstance'; cast the message send to the method's return type
error: 1 errors parsing expression
这到底是怎么回事?来自代码内部的调用似乎进展顺利。但调试器经常失败。在相同的上下文中,我可以访问其他的单例(使用相同的模式)

值得注意的是,loadData方法只是从磁盘加载一个字典,类上属性的getter使用该字典中的值,而不是ivar

以下是loadData的代码:

-(void)loadData
{
    // Load data from persistent storage
    NSString *path = [self pathToDataFile];
    NSMutableDictionary *settingsDict = [NSMutableDictionary dictionaryWithDictionary:[NSKeyedUnarchiver unarchiveObjectWithFile:path]];
    _settingsDict = settingsDict;
}

现在我无法解释原因,但将类从“设置”重命名为其他名称解决了问题。我在符号导航器中看不到任何与此名称冲突的内容。。。确实很奇怪。

正如您所看到的,
lldb
正在寻找
-sharedInstance
,这是一种实例方法,而不是类方法。查看是否有帮助。它完全独立于类名。我在
AVMediaTypeAudio
中遇到了相同的错误。它是一个系统常量,似乎无法在调试器中使用它