【问题标题】:How can this simple code fail assertion?这个简单的代码怎么会导致断言失败?
【发布时间】:2013-07-19 09:59:06
【问题描述】:
    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 到底是什么?

【问题讨论】:

  • 他的 iPhone 有什么特别的吗?比如是不是越狱了。
  • 我推荐一个干净的构建。

标签: objective-c ios6


【解决方案1】:

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

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

【讨论】:

  • 其实这是真的。你怎么知道的?
  • 不确定,但 Apple 不允许在 JB(越狱)设备中调试 :)
【解决方案2】:

不能保证从属性中读取会返回完全相同的值。

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-30
    • 2013-08-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多