While saving application content at rest or sending it with a network request you need to convert text into data, and with a single line of code, you can do that:
1
let stringData = Data(yourString.utf8)
Here, I have used the utf8 encoding, you can choose depending on your content.
And if you want to convert data to string:
1
let string = String(data: yourData, encoding: .utf8)