Xcode: directory file for simulator Iphone

后端 未结 8 1106
[愿得一人]
[愿得一人] 2021-01-30 03:25

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 cod

8条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-30 03:54

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

    The documents directory are now hidden within:

    ~/Library/Developer/CoreSimulator/Devices//data/Containers/Data/Application/
    

    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!

提交回复
热议问题