Xcode:模拟器Iphone的目录文件

Cra*_*Dev 24 string iphone directory xcode writetofile

我想在文件"file.txt"中写一个字符串:我的项目中的这个文件(对于Iphone)在Resources中; 我尝试在这个文件中写一个字符串,但它不起作用,我显示我的代码.

 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];
Run Code Online (Sandbox Code Playgroud)

我想用模拟器xcode写这个文件,而不是用设备

Jor*_*rge 49

我不确定您是否能够在您的软件包中写入,但您可以在您的文档目录中代替您的代码.你为什么不尝试这个?

使用相同的代码,您将在以下位置找到您的文件:

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


rch*_*ier 19

这改变了XCode 6和iOS 6,这很棘手.

文档目录现在隐藏在:

~/Library/Developer/CoreSimulator/Devices/<some-id>/data/Containers/Data/Application/<some-other-id>
Run Code Online (Sandbox Code Playgroud)

看起来每个应用程序启动时位置都在变化,因此很难跟踪.我从这篇文章中借用了一个简单的提示,我将为懒惰提供:

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

例如,将此添加到您的applicationDidFinishLaunching方法中,应该更容易!

如果您想了解更多详细信息,请查看原始文章

注意:我知道这个问题很老,但是我在搜索时发现了这个问题,所以我认为添加一个更新的答案可能会为我们中的一些人服务!


Mat*_*ick 15

模拟器中应用程序的Documents目录位于;

~/Library/Application Support/iPhone Simulator/YOUR-IOS-VERSION/Applications/UNIQUE-KEY-FOR-YOUR-APP/Documents
Run Code Online (Sandbox Code Playgroud)


Vit*_*lii 8

在应用程序的任何位置停止断点并在调试器中键入"po NSHomeDirectory()".使用Finder的Go> Go To Folder功能直接跳转到那里. 调试器中的