Contents

archiveRootObject(_:toFile:)

Creates a temporary instance of NSArchiver and archives an object graph by encoding it into a data object and writing the resulting data object to a specified file.

Declaration

class func archiveRootObject(_ rootObject: Any, toFile path: String) -> Bool

Parameters

  • rootObject:

    The root object of the object graph to archive.

  • path:

    The location of the file into which to write the archive.

Return Value

true if the archive was written successfully, otherwise false.

Discussion

This convenience method invokes archivedData(withRootObject:) to get the encoded data, and then sends that data object the message write(toFile:atomically:), using path for the first argument and true for the second.

The archived data should be retrieved from the archive by an NSUnarchiver object.

See Also

Related Documentation

Archiving data