uint8_t*buf=(uint8_t*) [characteristic.value bytes];
_textField.text=[NSString stringWithFormat:@"%d", buf[0]];
I'd like to write this Objective-C code on Swift, but I don't know how to write it well.
I would appreciate it if you could let me know
Write as follows or
var data=characteristic.value
var bytes = [UInt8] (count: data.length, repeatedValue:0)
data.getBytes(&bytes,length:data.length)
textField.text="\(bytes[0])"
Alternatively, the following may be closer to the original Objective-C code.
var data=characteristic.value
letptr = UnsafePointer<UInt8> (characteristic.value.bytes)
let bytes = UnsafeBufferPointer<UInt8> (start:ptr, count:data.length)
textField.text="\(bytes[0])"
886 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
568 Who developed the "avformat-59.dll" that comes with FFmpeg?
599 GDB gets version error when attempting to debug with the Presense SDK (IDE)
567 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
© 2024 OneMinuteCode. All rights reserved.