我正在尝试更新操作 ( HMCharacteristicWriteAction
) 的目标值,但它总是因 EXC_BAD_ACCESS (code=1, address=0x50) 而崩溃。
我的代码片段:
print("\(action) --> \(action.dynamicType)") // <HMCharacteristicWriteAction: 0x14cf7ba20> --> HMCharacteristicWriteAction
print("current: \(action.targetValue)") // current: 1
print("next: \(value) --> \(value.dynamicType)") // next: 0 --> Int
action.updateTargetValue(value, completionHandler: { [weak self] error -> Void in
if let error = error {
// display some message
return
}
// do something else when succeeded
})
如您所见,action
is 不是 nil 并且类型正确 ( HMCharacteristicWriteAction
)。我可以targetValue
成功阅读它。
我使用 分析了项目Product - Analyze
,一切正常(没有任何警告)。我也启用了 Zombie,Scheme - Diagnostics
但仍然没有运气。
根据updateTargetValue
文档:
/*!
* @brief This method is used to change target value for the characteristic.
*
* @param targetValue New target value for the characteristic.
*
* @param completion Block that is invoked once the request is processed.
* The NSError provides more information on the status of the request, error
* will be nil on success.
*/
public func updateTargetValue(targetValue: NSCopying, completionHandler completion: (NSError?) -> Void)
让我困惑的是targetValue: NSCopying
。是否符合“NSCopying”的Int
类型?value
我确实尝试value as NSCopying
过,targetValue
但并没有更好。
你能告诉我如何解决这个问题吗?可以通过Int
totargetValue
吗?什么可能导致此崩溃?
谢谢你。