Saving Data in iOS - Part 6: Section 1: String | Ray Wenderlich

Convert between bytes, Data instances, and Strings. They're all easily interchangeable when your data bytes represent Strings using your expected encoding.

This is a companion discussion topic for the original entry at

This line

try mysteryData.write(to: mysteryDataURL.appendPathExtension("txt"))

operates on a constant mysteryDataURL and my playground gives me an error to change ‘let’ to ‘var’ to make mysteryDataURL mutable. But yours isn’t mutable either… why aren’t you getting the same error?

Subtle difference in API! You’re using appendPathExtension, which mutates a URL.

We used appendingPathExtension, which creates a new URL based on a previous URL.

Swift is full of this “ing”/non-“ing” stuff now. It can be tricky when paired with autocomplete. Sorry it bit you!

This topic was automatically closed after 166 days. New replies are no longer allowed.

Hey @jessycatterwaul,

I was wondering if you might now how to do the following. I have been pulling my hair out and scouring the internet trying to piece together information regarding it.

I am wanting to take a Swift class instance, and convert it into its binary data, so I can perform an XOR, and store the difference between two different instances. I would then apply or remove the stored xor result to move between the two states. Kind of like an undo/redo.

I have been pulling my hair out trying to wrap my hair around Swifts Data, and converting data to bytes.

Any help would be awesome, Thanks :slight_smile: