I am trying to update target value of an action (HMCharacteristicWriteAction
) but it always crashes with EXC_BAD_ACCESS (code=1, address=0x50).
My code snippet:
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
})
As you see, action
is not nil and of correct type (HMCharacteristicWriteAction
). I can read its targetValue
successfully.
I analyzed the project using Product - Analyze
, everything is ok (no any warnings). I also enabled Zombie in Scheme - Diagnostics
but still no luck.
According to updateTargetValue
documentation:
/*!
* @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)
What confuses me is targetValue: NSCopying
. Does type Int
of value
conform 'NSCopying'? I did try value as NSCopying
for targetValue
but it is not better.
Could you please show me how to solve this problem? Is it ok to pass an Int
to targetValue
? What could cause this crash?
Thank you.