Instance Method

writeToURL:error:

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

Declaration

- (BOOL)writeToURL:(NSURL *)url error:(NSError * _Nullable *)error;

Parameters

url

The URL to which to write the dictionary.

error

On failure, a reference to the error that occurred.

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. The method populates error if all the objects are not property list objects, because the resulting output wouldn’t be a valid property list.

If the dictionary’s contents are all property list objects, you can use the location written by this method to initialize a new dictionary with 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:atomically:

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

Deprecated
- writeToFile:atomically:

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

Deprecated