【问题标题】:RKObjectManager's deleteObject with EXC_BAD_ACCESSRKObjectManager 的带有 EXC_BAD_ACCESS 的 deleteObject
【发布时间】:2013-12-19 18:57:31
【问题描述】:

当尝试使用对象向服务器发送 DELETE 请求时,如果您像这样填充 success 块,RestKit 会尝试引用已释放的对象:

[[APIClient objectManager] deleteObject:object path:path parameters:nil 
success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
  success();
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
  failure([error localizedDescription]);
}];

success() 回调目前什么都不做,因为我注意到 RestKit 会自动为我们删除本地 Core Data 对象。

如果我将success 块设置为nil,那么一切都很好,但我宁愿有办法知道它是成功的。

我猜它试图在映射结果中引用已删除的对象,但我不能确定。服务器只返回一个no content 标头,所以没有什么要映射的。

是不是我做错了什么导致了这种情况?

【问题讨论】:

  • 把你的块叫做别的东西(所以在讨论中很清楚)——你调用的块是存在还是为零?

标签: ios objective-c core-data restkit restkit-0.20


【解决方案1】:

为了安全起见,请将代码重写为:

[[APIClient objectManager] deleteObject:object path:path parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
    if (success != nil) {
        success();
    }
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
    if (failure != nil) {
        failure([error localizedDescription]);
    }
}];

因为尝试执行nil 块是一件坏事。

另外,当您定义successfailure 的属性时,请确保将它们设置为copy(而不是strong)。

【讨论】:

  • 正确。这是一个如此明显的错误,我只是想多了。感谢您的澄清。
猜你喜欢
  • 1970-01-01
  • 2012-01-22
  • 2011-01-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多