Saving Data in iOS · Challenge: URLs | Ray Wenderlich


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/6307-saving-data-in-ios/lessons/4

Hey guys,

Quick question: I was under the impression that, “challengeURL” will do nothing else than appending “challengeString” to “filePath”. But when I tap into lastPathComponent of the filePath, I get something else. Why is that?

image

Hi @peter0123,

What you’re seeing there looks like what I’d expect. What is the “something else” that you’re referring to?

I think maybe you’re expecting filePath to be mutated? You can make that happen, but you’d need to alter your code to this:

let challengeString = "Some string goes here"
var filePath = FileManager.documentDirectoryURL
filePath = URL(fileURLWithPath: challengeString, relativeTo: filePath ).appendingPathExtension("txt")

Hi @jessycatterwaul,

yep, that’s what I was looking for. I was expecting to see the filePath mutated. Now I’ve got it. So the filePath needs to point to FileManager.documentDirectoryURL.

Thank you.

Great course, by the way. I was a bit disappointed some months ago, because I couldn’t get the point of some of your examples ( struct challenges → restaurant challenge).

But once I tuned into your teaching style, thinks started to make a lot of sense. I guess I needed to take some time, and let the knowledge sink in.

The encoding /decoding json & saving data to iOS is simply amazing. It feels like I’ve been living in a dark room, and you’re just turned the light on.

Thank you :call_me_hand:

1 Like