Swift, 而不是 Object-C: 如何将 UInt8 / 16 转换为 String?

29 浏览
0 Comments

Swift, 而不是 Object-C: 如何将 UInt8 / 16 转换为 String?

这个问题已经有答案了:

将Int转换为String在Swift中

我正在使用Swift而不是Object-C开发的项目中,我需要将通过BLE特征提取的UInt16转换为字符串,以便我可以将其用作标签的文本。

已经有人解决了这个问题吗?

提前感谢您的帮助。

var currentValue: UInt16!
func peripheral(peripheral: CBPeripheral!, didUpdateValueForCharacteristic characteristic: CBCharacteristic!, error: NSError!) {
   if characteristic.UUID == xgatt_io_p_1 {
      let data = characteristic.value
      let reportData = UnsafePointer(data.bytes)
      currentValue = reportData.memory
   }
   readValue()
}
label.text = convertedCurrentValue

admin 更改状态以发布 2023年5月22日
0
0 Comments

你可以这样做:

label.text = "\(convertedCurrentValue)"

0