Instance Method

write(to:)

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

Declaration

func write(to url: URL) throws

Parameters

url

The URL to which to write the dictionary.

Return Value

true if the location is written successfully, otherwise false.

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 throws an 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 init(contentsOf:).

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

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

See Also

Storing Dictionaries

func write(to: URL, atomically: Bool) -> Bool

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

Deprecated
func write(toFile: String, atomically: Bool) -> Bool

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

Deprecated