views:

1079

answers:

6

Is it possible to read a file (from my normal file system) into a iPhone App running on the iPhone Simulator?

I understand that the iPhone itself has not got a (user accessible) file system but this is simply for testing and will only ever be run in the simulator.

The file will be a text file that can be edited while the application is running, it will be read every-time a method is called.

A: 

No. Your app is running in its own sandbox on the phone. It's not allowed to read or write outside of it.

Edit: I think CiNN is correct. As long as your code stays on the simulator, you shouldn't have problems working with a file on your local drive.

Tim Rupe
But you could make a connection (via TCP) to a little program you write to feed it the data.
MBCook
+1  A: 

Yes, you can if your file is within your app folder ~/Library/Application Support/iPhone Simulator/User/Applications/ [your app folder] /Documents

CiNN
It should be noted that this is identical to what you can do on the iPhone, i.e. NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
I'm pretty sure you can in general (I just tested it) - why does it have to be in the /Documents folder?
Jesse Beder
because it's easier to switch to device
CiNN
+5  A: 

Yes, you can, and it doesn't matter where it is. Just give it an absolute path name when you load it (Xcode won't recognize a different working directory when running the simulator).

Jesse Beder
A: 

I personally think that the easiest way would be to enter "file:///" in Safari within the simulator, if thats what your looking for.

iTz Sillohsk8
A: 

It should also be noted that you can do this in reverse -- you can grab the files off your hard drive that your application created in the simulator. This is a good way to check out your results (data, images, whatever) without having to build a data "viewer" into the application.

Amagrammer
A: 

FYI 'newer' sds versions will do this... Search for iPad and you will find it. (for obvious reasons I cannot give more details here) good luck.

me i