string Xcode:模拟器 Iphone 的目录文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5593064/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Xcode: directory file for simulator Iphone
提问by cyclingIsBetter
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.
我想在文件“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];
I want write in this file with simulator xcode, not with device
我想用模拟器 xcode 写这个文件,而不是用设备
回答by Jorge
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?
我不确定您是否能够在您的包中写入,但是您可以在您的 Documents 目录中而不是像您的代码那样。你为什么不试试这个?
Use the same code and you will find your file in:
使用相同的代码,您将在以下位置找到您的文件:
/Users/YOURUSER/Library/Application Support/iPhone Simulator/IOSVERSION/Applications/APPID/Documents/file.txt
/Users/ YOURUSER/Library/Application Support/iPhone Simulator/ IOSVERSION/Applications/ APPID/Documents/file.txt
回答by rchampourlier
This changed with XCode 6 and iOS 6 and this got tricky.
这在 XCode 6 和 iOS 6 中发生了变化,这变得很棘手。
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 articleand 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!
例如,将此添加到您的applicationDidFinishLaunching
方法中,应该会更容易!
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!
注意:我知道这个问题很旧,但是我在搜索时找到了它,所以我认为添加更新的答案可能对我们中的一些人有用!
回答by Matthew Frederick
The Documents directory for your app in the simulator is located at;
模拟器中应用程序的 Documents 目录位于;
~/Library/Application Support/iPhone Simulator/YOUR-IOS-VERSION/Applications/UNIQUE-KEY-FOR-YOUR-APP/Documents
回答by Vitalii
回答by Scott Little
With the example code that you have here it will not write into your Resources folder, but into the Documents folder of the Simulator, which is actually where you should write on device, but as you mention that you only want to do this on the simulator, you could use
使用您在此处提供的示例代码,它不会写入您的 Resources 文件夹,而是写入模拟器的 Documents 文件夹,这实际上是您应该在设备上编写的位置,但正如您提到的,您只想在模拟器上执行此操作,你可以使用
filePath = [[NSBundle mainBundle] bundlePath] stringByAppendingPathComnponent:@"Resources"]
But, don'tdo this in a shipping app, it will fail.
但是,不要在运输应用程序中执行此操作,它会失败。
回答by Robert
Paste this in the terminal.
将其粘贴到终端中。
open ~/Library/Application\ Support/iPhone\ Simulator/
回答by Jong Su Park
In gdb, stop process and paste it, then the location of Documents will be printed.
[[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject]
在 gdb 中,停止进程并粘贴它,然后将打印 Documents 的位置。
[[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject]
po [[[NSFileManager defaultManager] URLsForDirectory:9 inDomains:1] lastObject]
回答by codercat
If you are using Xcode 7 and higher follow this:
如果您使用的是 Xcode 7 及更高版本,请遵循以下步骤:
Documents Directory:
文件目录:
file:///Users/codercat/Library/Developer/CoreSimulator/Devices/YourProjectDict/data/Containers/Data/Application/(sample digit)7F53CFB3-C534-443F-B595-62619BA808F2/Documents/your file located here