Why Data and NSData print differently

落花浮王杯 提交于 2019-12-24 09:40:25

问题


This will, I'm sure, point out my knowledge gap. But I don't seen anything about this in the S.O. knowledge banks and looking at the foundation code has not shed any light for me.

Basic question: why does Swift's Data print differently than NSData?

e.g.

func getData(_ data:Data) {
    print("The TLV was: \(data as NSData)")
}

prints:

The TLV was: <020101>

But ...

func getData(_ data:Data) {
    print("The TLV was: \(data)")
}

prints:

The TLV was: 3 bytes

Thanks.


回答1:


"Data from Swift 3 has no "built-in" method to print its contents as a hex string, or to create a Data value from a hex string."

rmaddy was right.

Also see:

hex/binary string conversion in Swift



来源:https://stackoverflow.com/questions/44830747/why-data-and-nsdata-print-differently

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!