I tried send my struct parameters to remote device with swift CoreBluetooth library but I stack into copy struct parameters to array. Actually did the same thing in Windows application in c# but swift syntax and code style is very different and I couldn't make it.
You can find My code below
struct Test_Struct {
var value1 : UInt32
var value2 : UInt32
var value3 : UInt8
}
var data : [Test_Struct]=[]
data.append(Test_Struct(value1: 1000, value2: 2000, value3: 02))
I also tried something like below
var data = Test_Struct.init(value1: <UInt32>, value2: <UInt32>, value3: <UInt8>)
data.value1 = 1000
data.value2 = 1000
data.value3 = 1000
both code give me no error but when I tried to add "my var" to peripheral.writeValue(data, for: myChractaristic, type: CBCharacteristicWriteType.withoutResponse) I get an error. I also tried to add "var data" to Data or NSData but never worked for me.
For the summarize I need copy to struct some array like Byte[] array=data_struct and I send array value with BLE write value command.
Thanks in Advance.