Converting between String and Data without optionalsBasics article available: Strings
While Swift offers many APIs for converting between
String, these two let us do so without any optionals — usually resulting in simpler code:
// String -> Data let data = Data("Hello, world!".utf8) // Data -> String let string = String(decoding: data, as: UTF8.self)
Support Swift by Sundell by checking out this sponsor:
Raycast: Take the macOS Spotlight experience to the next level: Create Jira issues, manage GitHub pull requests and control other tools with a few keystrokes. Easily automate every-day tasks and boost your developer productivity by downloading Raycast for free.