Instance Method


Creates a file with the specified content and attributes at the given location.


- (BOOL)createFileAtPath:(NSString *)path contents:(NSData *)data attributes:(NSDictionary<NSFileAttributeKey, id> *)attr;



The path for the new file.


A data object containing the contents of the new file.


A dictionary containing the attributes to associate with the new file. You can use these attributes to set the owner and group numbers, file permissions, and modification date. For a list of keys, see NSFileAttributeKey. If you specify nil for attributes, the file is created with a set of default attributes.

Return Value

YES if the operation was successful or if the item already exists, otherwise NO.


If you specify nil for the attributes parameter, this method uses a default set of values for the owner, group, and permissions of any newly created directories in the path. Similarly, if you omit a specific attribute, the default value is used. The default values for newly created files are as follows:

  • Permissions are set according to the umask of the current process. For more information, see umask.

  • The owner ID is set to the effective user ID of the process.

  • The group ID is set to that of the parent directory.

If a file already exists at path, this method overwrites the contents of that file if the current process has the appropriate privileges to do so.

See Also

Creating and Deleting Items

- createDirectoryAtURL:withIntermediateDirectories:attributes:error:

Creates a directory with the given attributes at the specified URL.

- createDirectoryAtPath:withIntermediateDirectories:attributes:error:

Creates a directory with given attributes at the specified path.

- removeItemAtURL:error:

Removes the file or directory at the specified URL.

- removeItemAtPath:error:

Removes the file or directory at the specified path.