Working with directories and files in Sandbox

Home Directory

Naturally, you’d have the documents folder in your home directory as well:

which will give you something like this:

homeDir is: /var/mobile/Applications/DF2ACE23-C3D0-444B-9D25-7E56F102595A/Documents

This is where you save your files in your sandbox.

Writing text to a txt file

First, you have to get the name of your path + file. Something like this:

/var/mobile/Applications/DF2ACE23-C3D0-444B-9D25-7E56F102595A/Documents/test.txt

We do this by appending our file name to the home directory. In our case, let’s say self.filename is test.txt:

Then you use that path string and use method writeToFile: to write contents to that file:

full method:

Reading text from file in sandbox

Writing image to your sandbox

We first create an image. Make sure the image resource exists.
Then we give it a string name and then make sure homeDir is same as we’ve displayed above. Plug in and use like so:

where myFile.homeDir is: /var/mobile/Applications/DF2ACE23-C3D0-444B-9D25-7E56F102595A/Documents

Reading images from your sandbox

Used like this:

Implementation:

Leave a Reply