iOS Swift数据类型与Data的转换

2022-08-04  本文已影响0人  Lee坚武
本人亲测有效!更多交流可以家魏鑫:lixiaowu1129,公重好:iOS过审汇总,一起探讨iOS技术!

字符串与Data的转换

var send: String  = "hello"
let data: Data = send.data(using: .utf8)!

let receive: String = String(data: data, encoding: .utf8)!
print(receive)

Int与Data的转换

var send1: Int = 199
var data1: Data = Data(bytes: &send1, count: 8)

var receive1: Int = 0
(data1 as NSData).getBytes(&receive1, length: 8)
print(receive1)

本文由mdnice多平台发布

上一篇下一篇

猜你喜欢

热点阅读