Several methods I've used to write to files return a BOOL signifying their success, e.g.
NSDictionary:
- (BOOL) writeToFi开发者_开发百科le:(NSString *)path atomically:(BOOL)flag
NSKeyedArchiver:
- (BOOL) archiveRootObject:(id)rootObject toFile:(NSString *)path
Somehow, this returned NO on one of my tester's devices. That's great (well, not really), but is there anyway to find out why these operations might have failed?
The modern way is to create NSData from the (root object|dictionary), then write that data to the desired path using writeToFile:options:error:
or writeToURL:options:error:
. These methods return an NSError object by reference, which contains a description of what happened, including (in at least some cases) a user-presentable error message.
To create data representing a dictionary, use NSPropertyListSerialization
(if the dictionary and all of its contents, all the way down, are a valid property list) or the archiver (if not).
精彩评论