Instance Method

writeToURL:atomically:

Writes a property list representation of the contents of the dictionary to a given URL.

Declaration

- (BOOL)writeToURL:(NSURL *)url atomically:(BOOL)atomically;

Parameters

aURL

The URL to which to write the dictionary.

flag

A flag that specifies whether the output should be written atomically.

If flag is YES, the dictionary is written to an auxiliary location, and then the auxiliary location is renamed to aURL. If flag is NO, the dictionary is written directly to aURL. The YES option guarantees that aURL, if it exists at all, won’t be corrupted even if the system should crash during writing. flag is ignored if aURL is of a type that cannot be written atomically.

Return Value

YES if the location is written successfully, otherwise NO.

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 output would not be a valid property list.

If the dictionary’s contents are all property list objects, the location written by this method can be used to initialize a new dictionary with the class method dictionaryWithContentsOfURL: or the instance method initWithContentsOfURL:.

If you need greater control over the property list representation, use NSPropertyListSerialization instead.

For more information about property lists, see Property List Programming Guide.

See Also

Storing Dictionaries

- writeToURL:error:

Writes a property list representation of the contents of the dictionary to a given URL.

- writeToFile:atomically:

Writes a property list representation of the contents of the dictionary to a given path.

Deprecated