这个简单的代码如何失败断言?

时间:2013-07-19 09:59:07

标签: objective-c ios6

    PO(self);
    PO(_locationManager.delegate);
    PO([CLLocationHandler singleton]);
    _locationManager = [[CLLocationManager alloc] init];
    _locationManager.delegate = self;
    PO(self);
    PO(_locationManager.delegate);
    NSAssert(_locationManager.delegate==self,@"They are meant for each other");

因此,此代码适用于模拟器和大多数iPhone。有一个神奇的iPhone属于我的商业伙伴,我无法调试程序。

如果我直接运行已安装的程序,代码将产生:

<Warning>: *** -[NSKeyedUnarchiver initForReadingWithData:]: data is NULL
<Warning>: self: <CLLocationHandler: 0x1f8df560>
<Warning>: _locationManager.delegate: (null) <Warning>: [CLLocationHandler singleton]: <CLLocationHandler: 0x1f8df560>
<Warning>: self: <CLLocationHandler: 0x1f8df560>
<Warning>: _locationManager.delegate: <RwXSxTb_DelegateProxy: 0x1e594d00>
<Warning>: *** Assertion failure in -[CLLocationHandler additionalInitialization], /business/Dropbox/badgers/BadgerNew/CLLocationHandler.m:251
<Error>: *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'They are meant for each other'

什么是delegateProxy?

2 个答案:

答案 0 :(得分:3)

可能是您正在调试的设备是JB(Jail Break)。

因此,您无法在该设备中进行调试。

答案 1 :(得分:2)

无法保证从属性读取将返回完全相同的值。

属性是用于调用getter和setter方法的语法糖,这些方法可以做任何事情。

在您的情况下,-[CLLocationHandler setDelegate:]似乎将值包装在代理中。尝试将对象与isEqual:进行比较,许多代理将正确处理。

相关问题