---
title: "peripheral(_:didWriteValueFor:error:)"
framework: corebluetooth
role: symbol
role_heading: Instance Method
path: "corebluetooth/cbperipheraldelegate/peripheral(_:didwritevaluefor:error:)-4f5ea"
---

# peripheral(_:didWriteValueFor:error:)

Tells the delegate that the peripheral successfully set a value for the characteristic.

## Declaration

```swift
optional func peripheral(_ peripheral: CBPeripheral, didWriteValueFor characteristic: CBCharacteristic, error: (any Error)?)
```

## Parameters

- `peripheral`: The peripheral providing this information.
- `characteristic`: The characteristic containing the value.
- `error`: The reason the call failed, or nil if no error occurred.

## Discussion

Discussion Core Bluetooth invokes this method only when your app calls the writeValue(_:for:type:) method with the CBCharacteristicWriteType.withResponse constant specified as the write type. If successful, the error parameter is nil. If unsuccessful, the error parameter returns the cause of the failure.

## See Also

### Writing Characteristic and Descriptor Values

- [peripheral(_:didWriteValueFor:error:)](corebluetooth/cbperipheraldelegate/peripheral(_:didwritevaluefor:error:)-1ybl3.md)
- [peripheralIsReady(toSendWriteWithoutResponse:)](corebluetooth/cbperipheraldelegate/peripheralisready(tosendwritewithoutresponse:).md)
