Plist not saving from dictionary (to Documents)

2019-07-19 18:31发布

I've been trying to save a plist of a NSDictionary to my app's Documents folder. I haven't tried this on the device yet but I'd like it to work on the simulator for testing purposes. The [self createDictionaryFromChoreList] method just creates a NSDictionary from some data in another class of mine. I've pretty much copied/pasted this code from the web documents and when I go to see if the file was saved or not, I find that it isn't. Here is the method block.

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *plistName = [[NSString alloc] initWithFormat:@"%@chores.plist", self.firstName];
NSString *path = [documentsDirectory stringByAppendingPathComponent:plistName];

NSDictionary *choresDictionary = [[NSDictionary alloc] initWithDictionary:[self createDictionaryFromChoreList]];
[choresDictionary writeToFile:path atomically:YES];

Any help is greatly appreciated. Thanks in advance.

-S

7条回答
Emotional °昔
2楼-- · 2019-07-19 19:22

Is it correct, that the name of file your writing to is: SOEMTHINGchores.plist?

Created via:

NSString *plistName = [[NSString alloc] initWithFormat:@"%@chores.plist", self.firstName];

Also, what is the output of:

[choresDictionary print];

Some additional info would help to debug this.

查看更多
登录 后发表回答