Saving On Device | raywenderlich.com


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

Hi,

When I moved the file from the lesson 12 resources directory to the app’s Document directory I get a run time error saying it cannot find the file in the original location. If, instead, I copy it so it exists in both locations, then there is no runtime error.

If I rename the file in the Resources directory and then take the extra step to Xcode -> Product -> Clean Build Directory then it works with the file only in the Documents directory.

My question, since I am a newbie, is whether the Clean Build Directory is always needed or if it is sometimes done automatically?

Thank you for your question. What is happening, from what you describe in the first paragraph, is that you are loading the file from the bundle at first, and then when it gets copied it loads it from the sandbox. This is why, at a certain point, it will look for it in both places and why copying it is achieving good results.

As for having to clean things. Xcode works with what is know as “Derived Data”, and it’s a folder that sometimes contains build results, cached data and files, or other things to speed up the build process or to cache build results.

If you are noticing odd behavior it can sometimes be due to that derived data being stale or out-of-date. What is usually done then is cleaning, as you did, and then building and running again.

You can see the contents of this folder by going to Xcode -> Locations, and clicking in the arrow (if I recall correctly) to take you there in Finder.

Have a look around, it’s fun to see and it’s something you may deal with as you work with iOS projects and Xcode :slight_smile:

Thank you for great explanation. Finally figured out what is the Bundle and where it’s actually located :raised_hands: