Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode: directory file for simulator Iphone

Tags:

i want to write a string in a file "file.txt": this file in my project (for Iphone) is inside Resources; I try to write a string in this file but it don't work, I show my code.

 NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *filePath =  [documentsDirectory stringByAppendingPathComponent:@"file.txt"]; NSError *error; [outputString writeToFile:filePath atomically:YES encoding:NSUTF8StringEncoding error:&error]; 

I want write in this file with simulator xcode, not with device

like image 925
cyclingIsBetter Avatar asked Apr 08 '11 09:04

cyclingIsBetter


People also ask

Where are iOS simulators stored?

type: ~/Library/Application Support/iPhone Simulator. The Directories are the iOS version of the different Simulators. The Sub Directories are the Apps install on the simulator. The Documents folder is where the user generated content which gets backup up onto iCloud.

How do I connect my iPhone to Xcode simulator?

Open up a project in Xcode and click on the device near the Run ▶ button at the top left of your Xcode screen. Plug your iPhone into your computer. You can select your device from the top of the list. Unlock your device and (⌘R) run the application.

How do I access iOS simulator files?

~/Library/Developer/CoreSimulator/Devices Once in a folder, go to Applications, choose the Finder option that shows date for files, and sort by date.


2 Answers

I'm not sure if you are able to write in your bundle, but you can in your Documents directory instead as your code does. Why don't you try this?

Use the same code and you will find your file in:

/Users/YOURUSER/Library/Application Support/iPhone Simulator/IOSVERSION/Applications/APPID/Documents/file.txt

like image 92
Jorge Avatar answered Sep 29 '22 23:09

Jorge


This changed with XCode 6 and iOS 6 and this got tricky.

The documents directory are now hidden within:

~/Library/Developer/CoreSimulator/Devices/<some-id>/data/Containers/Data/Application/<some-other-id> 

It seems the location is changing at each application start, so it's really hard to track. There is a simple tip I borrowed from this article and that I will include for the lazy ones:

#if TARGET_IPHONE_SIMULATOR // where are you? NSLog(@"Documents Directory: %@", [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject]); #endif 

Add this for example to your applicationDidFinishLaunching method, should make it easier!

If you want more details, just have a look to the original article

NB: I know the question is old, but well, I found it while searching, so I think adding an updated answer may serve some of us!

like image 45
Romain Champourlier Avatar answered Sep 29 '22 23:09

Romain Champourlier