Instance Method


Writes the value of a characteristic.


func writeValue(_ data: Data, for characteristic: CBCharacteristic, type: CBCharacteristicWriteType)



The value to be written.


The characteristic whose value is to be written.


The type of write to be executed. For a list of the possible types of writes to a characteristic’s value, see CBCharacteristicWriteType.


When you call this method to write the value of a characteristic, the peripheral calls the peripheral:didWriteValueForCharacteristic:error: method of its delegate object only if you specified the write type as CBCharacteristicWriteType.withResponse. The response you receive through the peripheral:didWriteValueForCharacteristic:error: delegate method indicates whether the write was successful; if the write failed, it details the cause of the failure in an error. If you specify the write type as CBCharacteristicWriteType.withoutResponse, the write is best-effort and not guaranteed. If the write does not succeed in this case, you are not notified nor do you receive an error indicating the cause of the failure. The data passed into the data parameter is copied, and you can dispose of it after the method returns.

Characteristics may allow only certain type of writes to be performed on their value. To determine which types of writes are permitted to a characteristic’s value, you access the relevant properties of the CBCharacteristicProperties enumeration, which are detailed in CBCharacteristic.

See Also

Writing Characteristic and Characteristic Descriptor Values

func writeValue(Data, for: CBDescriptor)

Writes the value of a characteristic descriptor.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software