writing NSDictionary to plist in my app bundle

前端 未结 2 1879
星月不相逢
星月不相逢 2020-11-27 20:25

I\'m trying to write an NSDictionary to a plist but when I open the plist no data has been written to it. From the log my path looks correct and my code is pretty standard.

相关标签:
2条回答
  • 2020-11-27 21:07

    Johan is right -- you're not allowed to modify your app's bundle. You have two good options for where to save your dictionary: the documents directory, which is backed up by iTunes when a user syncs their device; or the caches directory, which is not backed up. If you don't need to have the data backed up, put it in caches so you don't slow down syncing. You can get the directory paths like so:

    NSString *documentsDirectoryPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
    
    NSString *cachesDirectoryPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0];
    
    0 讨论(0)
  • 2020-11-27 21:10

    It doesn't get saved because you can't write into your app's bundle. Save your file elsewhere, in the documents folder for example.

    0 讨论(0)
提交回复
热议问题