Having problem in copying a dictionary to a specified location
I am trying to copy my root dictionary to an already set path by using the following statement:
[rootObj writeToFile:writableDBPath atomically:TRUE];
But the problem is that it is not able to c开发者_StackOverflow中文版opy rootObj
at the specified location.
rootObj
is a mutable dictionary of capacity 4 with 3 key-value pairs.
writableDBPath
also has a set value into my iPhone simulator's document folder.
What am I doing wrong?
You should check whether you are allowed to write to that path in the first place. Use NSFileManager
's isWritableFileAtPath:
method for that. If this succeeds, but you still can't write to a file, then maybe your objects are not serializable. From NSDictionary documentation:
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
As a last point, note that in Objective-C, you don't use TRUE, you use YES
(with NO
being its counterpart).
精彩评论