Swift 3 changes for getBytes method

后端 未结 2 2055
误落风尘
误落风尘 2021-02-05 11:01

I have tried to run the below code in swift 3

 var values = [UInt8](count:data!.length, repeatedValue:0)
 data!.getBytes(&values, length:data!.length)


        
相关标签:
2条回答
  • 2021-02-05 11:15

    It means that the arguments order has been reversed in Swift 3.

    For NSData:

    var values = [UInt8](repeating:0, count:data!.length)
    data.getBytes(&values, length: data!.length)
    

    For Data:

    var values = [UInt8](repeating:0, count:data!.count)
    data.copyBytes(to: &values, count: data!.count)
    
    0 讨论(0)
  • 2021-02-05 11:40

    For Swift3 just use following:

    let array = [UInt8](yourDataObject)
    

    That's all, folks!)

    0 讨论(0)
提交回复
热议问题