Saving Data in iOS - Part 3: Section 1: Paths | Ray Wenderlich

Find out what the difference is between a URL and a path, and learn how to create your own useful URLs.


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

Really great tutorials, just have one question regarding:

let stringURL = FileManager.documentDirectoryURL.appendingPathComponent(“string”).appendingPathExtension(“txt”)

I know that property stringUrl is a string url path. But is this creating an empty text document called “string.txt” in the user’s document directory, or is it a url path to a text document that does not exist called “string.txt”? Thanks.

The document will not exist until we write data to stringURL. So it’s the second situation you’ve asked about, that the URL represents. You can create URL instances without any fear of cluttering up the document directory, for example.

Side note: An important distinction is that stringURL is not a path itself, but an instance of Foundations’s URL struct. The URL has a path, which is just a string that holds what might elsewhere be called a URL. This terminology might be different in other environments, but it’ll be helpful to keep in mind for Cocoa Touch development.

1 Like

running into a few issues
what is shown in the video doesn’t line up with what I get. The issue is with what is shown when I hit the eye or check the box. is will give me a empty file rather then the text.

I tested the fact of me getting that empty file with that let statement below
it shows that fine but not the other.

Hey!

What you’re seeing is exactly what you should be seeing (even though it’s not very helpful! :upside_down_face:) You’re missing the .path property usage, which is the last thing we did in this video, on lines 6 and 9.

What is the difference between URL and Filemanager.default

FileManagers allow you to work with URLs.

1 Like

Sorry, but this episode stopped me
Do you mean that I can get the URL either by FileManager class or URL 
 could you explain this point 
 It missed in the video??
What is the URL for ??

Which URL in particular are you asking about?

thx jessy for your help
I wil read the links above
seems clear now

1 Like

I have this error
Playground execution failed:

error: MyPlayground.playground:5:1: error: instance member ‘documentDirectoryURL’ cannot be used on type ‘FileManager’
FileManager.documentDirectoryURL
^~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~

Although i did everything like video and save

@jessycatterwaul Can you please help with this when you get a chance? Thank you - much appreciated! :]

Also this error

error: Execution was interrupted, reason: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0).
The process has been left at the point where it was interrupted, use “thread return -x” to return to the state before expression evaluation.

I just checked out the “3 - End” version of the playground, and didn’t have this problem. My best guess is that you missed the static keyword, but it’s possible that you just didn’t wait long enough for the playground to compile. If you’re still having trouble, please upload your version and I’ll have a look at it!

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