In No hex dump anymore in Data description and SR-2514 I had reported that there is no native method to view the (full) contents of a Data value, and that a bridge to NSData can be used as a workaround.
Apparently that workaround does not work anymore in Xcode 11 beta 2, the description of NSData is truncated now:
let data = Data(1...255)
print(data)
// 255 bytes
print(data as NSData)
// {length = 255, bytes = 0x01020304 05060708 090a0b0c 0d0e0f10 ... f8f9fafb fcfdfeff }
Is this truncation of the NSData output an intentional change? Are there other methods now to print a full hex dump, or do we have to define our own method?
The change to NSData is probably intended; relying on the format of description never changing is fragile.
In terms of going from here, Data's description should mirror NSData in my opinion, a byte count alone is not very useful. There is also room for a hexadecimalString API that returns the data as hex; it is very commonly required and would warrant Foundation inclusion IMO.
Just to clarify: What I had in mind is a hex dump for debugging purposes (such as: βWhat data did the server send exactly?β, βWhy does the conversion from Data to String fail?β), not a reliable format for further processing.
Gotcha. Again, I think the truncated form currently used by NSData is a good balance, and then a separate property/method which generates a full string is there if you need it (for production or debugging purposes).
I did some more research: The truncation of the NSData output happens on macOS 10.15 (beta), but not on on 10.14.5, and also in an Objective-C program. So this seems to be a change in the Foundation library on Catalina, and unrelated to Swift.
It remains the question if Swift's Data should get a hexEncodedString() method.
If data is a collection, then if I will get a data from a bitmap, via the pngRepresetation, will its count (data.count) be exactly the same as count of bytes, which the png bitmap occupies on memory?
UPD. Answer is yes