This is a companion discussion topic for the original entry at https://www.raywenderlich.com/6307-saving-data-in-ios/lessons/6
This is a companion discussion topic for the original entry at https://www.raywenderlich.com/6307-saving-data-in-ios/lessons/6
Hi guys,
Thanks for the video. I have a very novel question. How does the string file return the four cat emojis when it takes the parameters of savedMysteryData? Considering savedMysteryData takes the parameters of mysteryDataURL, I don’t see how mysteryDataURL is able to link with the initial data (mysteryBytes or even mysteryData).
Hi!
This line saves the bytes to your drive:
try mysteryData.write(to: mysteryDataURL)
…and this line reads that file, and loads them back into memory:
let savedMysteryData = try Data(contentsOf: mysteryDataURL)
Of course, they have to be written in that order!
Ahh, I get you. So the line;
**let** string = String(data: savedMysteryData, encoding: .utf8)!
Is really recalling the data in String format rather than saving it again?
Thanks for the reply!
@jamiestirrat Do you still have issues with this?
Nope, all good. Thanks!