且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Swift CoreBluetooth从BLE读取浮点数组

更新时间:2023-01-24 08:19:15

这是我用于测试从数据表示形式获取浮点数数组的代码:

this is the code I used for testing getting an array of floats from Data representation :

    let arr: [Float] = [32.0, 4.0, 1.2]
    let data = Data(buffer: UnsafeBufferPointer(start: arr, count: arr.count))
    print("---> data: \(data)")

    var myFloatArray = Array<Float>(repeating: 0, count: data.count/MemoryLayout<Float>.stride)
    myFloatArray.withUnsafeMutableBytes { data.copyBytes(to: $0) }

    print("---> myFloatArray: \(myFloatArray)")