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

Obj C: Unable to access singleton from debugger

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

- (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 方法只是从磁盘加载一个字典,class 上的属性的 getter 使用该字典中的值,而不是 ivars。

这是加载数据的代码:

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

现在我无法解释原因,但是将 class 从 'Settings' 重命名为其他名称可以解决问题。我在 Symbol Navigator 中看不到任何与此名称冲突的内容...确实很奇怪。