I have the following, where path is the documents folder. myArray is an NSMutableDictionary. I'm running this in the simulator.

BOOL success = [self.myArray writeToFile:path atomically:YES];

The above always returns no. I can see in the target folder that nothing was written.

The path looks like this:

/Users/username/Library/Application Support/iPhone Simulator/7.1/Applications/79D8982F-9995-4831-83B9-E2749F2261CD/Documents/

Any ideas what I'm doing wrong?

有帮助吗?

解决方案

I expect one or more objects within the dictionary cannot be written:

Discussion

This method recursively validates that all the contained objects are property list objects (instances of NSData, NSDate, NSNumber, NSString, NSArray, or NSDictionary) before writing out the file, and returns NO if all the objects are not property list objects, since the resultant file would not be a valid property list.

Where Property List Objects are (see here):

NSArray, NSDictionary, NSString, NSData, NSDate and NSNumber.

其他提示

The path points to the Documents directory but not to any particular file in that directory. You can't write a file to a directory, you have to give it a file name. The other obvious possibility would be that self.myArray == nil. Plus what Droppy said is absolutely correct.

/Users/username/Library/Application Support/iPhone Simulator/7.1/Applications/79D8982F-9995-4831-83B9-E2749F2261CD/Documents/

The path just represents a navigation to Documents Directory but not pointing to some kind of file.

Add some file name with the below line and add dictionary to the path

NSArray *sandboxArray=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *path= [[arr objectAtIndex:0]stringByAppendingPathComponent:@"login.plist"];

write something similar to the path

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top