New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SR-2514] Add a "hex dump" method to Data
#4115
Comments
It's worth noting that, if Data.description returned a hex dump (or some other complete representation of the instance's contents), then we could provide a compatible Data.init(_: String) and then conform Data to LosslessStringConvertible. |
We do have a bug in radar for this (15719610). |
Casting to NSData does not help any more in Xcode 10/Swift 4.2: let data1 = Data(bytes: [1, 2, 3])
print(data1 as NSData) // Foundation._NSSwiftData
let data2 = "Hello world".data(using: .utf8)!
print(data2 as NSData) // _NSInlineData |
I'd be open to accepting a PR that improves struct Data's debugDescription to print out some actual bytes. |
On macOS 10.15 (Catalina) beta, the NSData output is now truncated: let data = Data(1...255)
// 255 bytes
print(data as NSData)
// {length = 255, bytes = 0x01020304 05060708 090a0b0c 0d0e0f10 ... f8f9fafb fcfdfeff } so that this workaround does not help anymore to get the (full) content of a Data value (for debugging purposes). |
Additional Detail from JIRA
md5: 641850a22679507d5d233e1d7021576d
Issue Description:
There should be a way to get the contents of a
Data
object in hexadecimal form.The description methods do not provide that, as it was the case with
NSData
:Of course I can cast to
NSData
but it would be nice to have a "native" method. Suggestions:
description
returns a hex dump, ordebugDescription
returns a hex dump, ora new
hexEncodedString
method, similar to the existing Base64 methods.The text was updated successfully, but these errors were encountered: