How to save file in the documents folder?

后端 未结 4 1142
半阙折子戏
半阙折子戏 2020-12-06 14:54

I am trying to save data in the documents folder on iPhone 5.1 simulator.

 NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDo         


        
4条回答
  •  清歌不尽
    2020-12-06 15:24

    Swap out your [NSString stringWithFormat:] for an [NSString stringByAppendingPathComponent:]. This makes or breaks your ability to create a viable path, or so my experience has taught me.

    Additionally, this sort of thing comes up when writing on the simulator vs a real device. The simulator is a lot more forgiving when you are saving things in the wrong paths than the device will be, and quite often you'll get the I/O working fine only to run into the notorious 'It works in the simulator!' pit. stringWithFormat: is just one way to fall in.

提交回复
热议问题