Instance Method

writeToFile:atomically:

Writes the contents of the array to a file at a given path.

Declaration

- (BOOL)writeToFile:(NSString *)path atomically:(BOOL)useAuxiliaryFile;

Parameters

path

The path at which to write the contents of the array.

If path contains a tilde (~) character, you must expand it with stringByExpandingTildeInPath before invoking this method.

flag

If YES, the array is written to an auxiliary file, and then the auxiliary file is renamed to path. If NO, the array is written directly to path. The YES option guarantees that path, if it exists at all, won’t be corrupted even if the system should crash during writing.

Return Value

YES if the file is written successfully, otherwise NO.

Discussion

If the array’s contents are all property list objects (NSString, NSData, NSArray, or NSDictionary objects), the file written by this method can be used to initialize a new array with the class method arrayWithContentsOfFile: or the instance method initWithContentsOfFile:. This method recursively validates that all the contained objects are property list objects 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.

See Also

Storing Arrays

- writeToURL:atomically:

Writes the contents of the array to the location specified by a given URL.

Deprecated