I couldn't find a solution to this problem in Swift (all of them are Objective-C, and they deal with pointers which I don't think exist in Swift in the same form). Is there any way to convert a NSData
object into an array of bytes in the form of [Uint8]
in Swift?
相关问题
- “Zero out” sensitive String data in Swift
- SwiftUI: UIImage (QRCode) does not load after call
- Get the NSRange for the visible text after scroll
- UIPanGestureRecognizer is not working in iOS 13
- What does a Firebase observer actually do?
相关文章
- Using if let syntax in switch statement
- Enum with associated value conforming to CaseItera
- Swift - hide pickerView after value selected
- Is there a Github markdown language identifier for
- How can I vertically align my status bar item text
- Adding TapGestureRecognizer to UILabel in Swift
- Attempt to present UIAlertController on View Contr
- Swift - Snapshotting a view that has not been rend
It's funny but exist more simple solution. Works in Swift 3. Surely. I've used this today.
That's all! :) NSData easily bridged to Data.
UPDATE: (due to Andrew Koster comment)
Swift 4.1, Xcode 9.3.1
Just has been rechecked - all works as expected.
Output: [84, 101, 115, 116, 83, 116, 114, 105, 110, 103] Optional("TestString")
Swift 3/4
Swift 5 Solution
Data to [bytes]
[bytes] to Data
You can use the
getBytes
function ofNSData
to get the byte array equivalent.As you did not provide any source code, I will use a Swift String contents that has been converted to NSData.
Swift 3/4
swift 4 and image data to a byte array.
You can try