问题
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)
where data is 'Data' datatype (NSData is change to 'Data' as per swift 3 guidelines)
I am not able to run the above code in Swift 3. Compiler gives error that "Argument Repeated value must precede argument". The same line of code was working in Swift 2.2
What will be the solution ?
回答1:
For Swift3 just use following:
let array = [UInt8](yourDataObject)
That's all, folks!)
回答2:
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)
来源:https://stackoverflow.com/questions/38097710/swift-3-changes-for-getbytes-method