How can I print the content of a variable of type Data using Swift?

ios, swift

Solution

Just

print(data! as NSData)

PS: Your expected hex is .utf8

Problem

All I am looking to do is take a string and get its hex value. I've been following this post. Here is the code I have in my playground: ``` let str = "Say Hello to My Little Friend" let data = str.data(using: String.Encoding.utf16) print("\(data!)") ``` However, my code just prints: "60 bytes\n" How can I print the hex value? For reference, it should be: ``` 5361792048656c6c6f20746f204d79204c6974746c6520467269656e64 ```

Original source

Related problems