アクション ( ) のターゲット値を更新しようとしていますHMCharacteristicWriteAction
が、常に EXC_BAD_ACCESS (コード = 1、アドレス = 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
は nil ではなく、正しい型 ( HMCharacteristicWriteAction
) です。正常に読み取ることができますtargetValue
。
を使用してプロジェクトを分析しましたProduct - Analyze
。すべて問題ありません (警告はありません)。ゾンビも有効にしまし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
. タイプInt
はvalue
「NSCopying」に準拠していますか? 試しvalue as NSCopying
てみましtargetValue
たが、良くありません。
この問題を解決する方法を教えてください。Int
toを渡しても大丈夫targetValue
ですか?このクラッシュの原因は何ですか?
ありがとうございました。