Class: NSFileManager

Inherits:
NSObject show all

Overview

The NSFileManager class enables you to perform many generic file-system operations and insulates an app from the underlying file system. Most file operations can be performed using the shared file manager object. In iOS and in OS X v10.5 and later, you can also create a unique instance of NSFileManager in cases where you want to use a delegate object in conjunction with the file manager.

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from NSObject

#!, #!=, #!~, #, #==, #===, #=~, #Rational, #__callee__, #__method__, #__send__, #__type__, `, alloc, allocWithZone:, #autoContentAccessingProxy, autoload, autoload?, autorelease_pool, #awakeAfterUsingCoder:, binding, block_given?, caller, cancelPreviousPerformRequestsWithTarget:, cancelPreviousPerformRequestsWithTarget:selector:object:, catch, class, classFallbacksForKeyedArchiver, #classForCoder, #classForKeyedArchiver, classForKeyedUnarchiver, #clone, conformsToProtocol:, #copy, copyWithZone:, #dealloc, #define_singleton_method, description, display, #doesNotRecognizeSelector:, #dup, #enum_for, #eql?, #equal?, #extend, fail, #finalize, format, #forwardInvocation:, #forwardingTargetForSelector:, framework, #freeze, #frozen?, getpass, gets, global_variables, initialize, #initialize_clone, #initialize_copy, #initialize_dup, #inspect, instanceMethodForSelector:, instanceMethodSignatureForSelector:, #instance_eval, #instance_exec, #instance_of?, #instance_variable_defined?, #instance_variable_get, #instance_variable_set, #instance_variables, instancesRespondToSelector:, isSubclassOfClass:, #is_a?, iterator?, #kind_of?, lambda, load, load_bridge_support_file, load_plist, local_variables, loop, #method, #methodForSelector:, #methodSignatureForSelector:, #methods, #mutableCopy, mutableCopyWithZone:, new, #nil?, open, p, #performSelector:onThread:withObject:waitUntilDone:, #performSelector:onThread:withObject:waitUntilDone:modes:, #performSelector:withObject:afterDelay:, #performSelector:withObject:afterDelay:inModes:, #performSelectorInBackground:withObject:, #performSelectorOnMainThread:withObject:waitUntilDone:, #performSelectorOnMainThread:withObject:waitUntilDone:modes:, print, printf, #private_methods, proc, #protected_methods, #public_method, #public_methods, #public_send, putc, puts, raise, rand, readline, readlines, #replacementObjectForCoder:, #replacementObjectForKeyedArchiver:, require, resolveClassMethod:, resolveInstanceMethod:, #respond_to?, #respond_to_missing?, select, #send, setVersion:, #singleton_methods, sprintf, srand, superclass, #taint, #tainted?, #tap, test, throw, #to_plist, #to_s, trace_var, trap, #trust, #untaint, untrace_var, #untrust, #untrusted?, version

Constructor Details

This class inherits a constructor from NSObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class NSObject

Class Method Details

+ (NSFileManager) defaultManager

Returns the shared file manager object for the process. This method always returns the same file manager object. If you plan to use a delegate with the file manager to receive notifications about the completion of file-based operations, you should create a new instance of NSFileManager (using the init method) rather than using the shared object.

Returns:

Instance Method Details

- (Hash) attributesOfFileSystemForPath(path, error:error)

Returns a dictionary that describes the attributes of the mounted file system on which a given path resides. This method does not traverse a terminal symbolic link.

Parameters:

  • path (String)

    Any pathname within the mounted file system.

  • error (Pointer)

    On input, a pointer to an error object. If an error occurs, this pointer is set to an actual error object containing the error information. You may specify nil for this parameter if you do not want the error information.

Returns:

  • (Hash)

    An NSDictionary object that describes the attributes of the mounted file system on which path resides. See “File-System Attribute Keys” for a description of the keys available in the dictionary.

- (Hash) attributesOfItemAtPath(path, error:error)

Returns the attributes of the item at a given path.

Parameters:

  • path (String)

    The path of a file or directory.

  • error (Pointer)

    On input, a pointer to an error object. If an error occurs, this pointer is set to an actual error object containing the error information. You may specify nil for this parameter if you do not want the error information.

Returns:

  • (Hash)

    An NSDictionary object that describes the attributes (file, directory, symlink, and so on) of the file specified by path. The keys in the dictionary are described in “File Attribute Keys”.

- (Boolean) changeCurrentDirectoryPath(path)

Changes the path of the current working directory to the specified path. All relative pathnames refer implicitly to the current working directory. Changing the current working directory affects only paths created in the current process.

Parameters:

  • path (String)

    The path of the directory to which to change.

Returns:

  • (Boolean)

    YES if successful, otherwise NO.

- (Array) componentsToDisplayForPath(path)

Returns an array of strings representing the user-visible components of a given path. These components cannot be used for path operations and are only suitable for display to the user.

Parameters:

  • path (String)

    A pathname.

Returns:

  • (Array)

    An array of NSString objects representing the user-visible (for the Finder, Open and Save panels, and so on) components of path. Returns nil if path does not exist.

- (NSData) contentsAtPath(path)

Returns the contents of the file at the specified path.

Parameters:

  • path (String)

    The path of the file whose contents you want.

Returns:

  • (NSData)

    An NSData object with the contents of the file. If path specifies a directory, or if some other error occurs, this method returns nil.

- (Boolean) contentsEqualAtPath(path1, andPath:path2)

Returns a Boolean value that indicates whether the files or directories in specified paths have the same contents. If path1 and path2 are directories, the contents are the list of files and subdirectories each contains—contents of subdirectories are also compared. For files, this method checks to see if they’re the same file, then compares their size, and finally compares their contents. This method does not traverse symbolic links, but compares the links themselves.

Parameters:

  • path1 (String)

    The path of a file or directory to compare with the contents of path2.

  • path2 (String)

    The path of a file or directory to compare with the contents of path1.

Returns:

  • (Boolean)

    YES if file or directory specified in path1 has the same contents as that specified in path2, otherwise NO.

- (Array) contentsOfDirectoryAtPath(path, error:error)

Performs a shallow search of the specified directory and returns the paths of any contained items. This method performs a shallow search of the directory and therefore does not traverse symbolic links or return the contents of any subdirectories. This method also does not return URLs for the current directory (“.”), parent directory (“..”), or resource forks (files that begin with “._”) but it does return other hidden files (files that begin with a period character). If you need to perform a deep enumeration, use the enumeratorAtURL:includingPropertiesForKeys:options:errorHandler: method instead.The order of the files in the returned array is undefined.

Parameters:

  • path (String)

    The path to the directory whose contents you want to enumerate.

  • error (Pointer)

    On input, a pointer to an error object. If an error occurs, this pointer is set to an actual error object containing the error information. You may specify nil for this parameter if you do not want the error information.

Returns:

  • (Array)

    An array of NSString objects, each of which identifies a file, directory, or symbolic link contained in path. Returns an empty array if the directory exists but has no contents. If an error occurs, this method returns nil and assigns an appropriate error object to the error parameter

- (Array) contentsOfDirectoryAtURL(url, includingPropertiesForKeys:keys, options:mask, error:error)

Performs a shallow search of the specified directory and returns URLs for the contained items. This method performs a shallow search of the directory and therefore does not traverse symbolic links or return the contents of any subdirectories. This method also does not return URLs for the current directory (“.”), parent directory (“..”), or resource forks (files that begin with “._”) but it does return other hidden files (files that begin with a period character). If you need to perform a deep enumeration, use the enumeratorAtURL:includingPropertiesForKeys:options:errorHandler: method instead.The order of the files in the returned array is undefined.

Parameters:

  • url (NSURL)

    The URL for the directory whose contents you want to enumerate.

  • keys (Array)

    An array of keys that identify the file properties that you want pre-fetched for each item in the directory. For each returned URL, the specified properties are fetched and cached in the NSURL object. For a list of keys you can specify, see Common File System Resource Keys.

  • mask (NSDirectoryEnumerationOptions)

    Options for the enumeration. Because this method performs only shallow enumerations, the only supported option is NSDirectoryEnumerationSkipsHiddenFiles.

  • error (Pointer)

    On input, a pointer to an error object. If an error occurs, this pointer is set to an actual error object containing the error information. You may specify nil for this parameter if you do not want the error information.

Returns:

  • (Array)

    An array of NSURL objects, each of which identifies a file, directory, or symbolic link contained in url. If the directory contains no entries, this method returns an empty array. If an error occurs, this method returns nil and assigns an appropriate error object to the error parameter.

- (Boolean) copyItemAtPath(srcPath, toPath:dstPath, error:error)

Copies the item at the specified path to a new location synchronously. When copying items, the current process must have permission to read the file or directory at srcPath and write the parent directory of dstPath. If the item at srcPath is a directory, this method copies the directory and all of its contents, including any hidden files. If a file with the same name already exists at dstPath, this method aborts the copy attempt and returns an appropriate error. If the last component of srcPath is a symbolic link, only the link is copied to the new path.Prior to copying an item, the file manager asks its delegate if it should actually do so for each item. It does this by calling the fileManager:shouldCopyItemAtURL:toURL: method; if that method is not implemented it calls the fileManager:shouldCopyItemAtPath:toPath: method instead. If the delegate method returns YES, or if the delegate does not implement the appropriate methods, the file manager copies the given file or directory. If there is an error copying an item, the file manager may also call the delegate’s fileManager:shouldProceedAfterError:copyingItemAtURL:toURL: or fileManager:shouldProceedAfterError:copyingItemAtPath:toPath: method to determine how to proceed.

Parameters:

  • srcPath (String)

    The path to the file or directory you want to move. This parameter must not be nil.

  • dstPath (String)

    The path at which to place the copy of srcPath. This path must include the name of the file or directory in its new location. This parameter must not be nil.

  • error (Pointer)

    On input, a pointer to an error object. If an error occurs, this pointer is set to an actual error object containing the error information. You may specify nil for this parameter if you do not want the error information.

Returns:

  • (Boolean)

    YES if the item was copied successfully or the file manager’s delegate aborted the operation deliberately. Returns NO if an error occurred.

- (Boolean) copyItemAtURL(srcURL, toURL:dstURL, error:error)

Copies the file at the specified URL to a new location synchronously. When copying items, the current process must have permission to read the file or directory at srcURL and write the parent directory of dstURL. If the item at srcURL is a directory, this method copies the directory and all of its contents, including any hidden files. If a file with the same name already exists at dstURL, this method aborts the copy attempt and returns an appropriate error. If the last component of srcURL is a symbolic link, only the link is copied to the new path.Prior to copying each item, the file manager asks its delegate if it should actually do so. It does this by calling the fileManager:shouldCopyItemAtURL:toURL: method; if that method is not implemented (or the process is running in OS X 10.5 or earlier) it calls the fileManager:shouldCopyItemAtPath:toPath: method instead. If the delegate method returns YES, or if the delegate does not implement the appropriate methods, the file manager proceeds to copy the file or directory. If there is an error copying an item, the file manager may also call the delegate’s fileManager:shouldProceedAfterError:copyingItemAtURL:toURL: or fileManager:shouldProceedAfterError:copyingItemAtPath:toPath: method to determine how to proceed.

Parameters:

  • srcURL (NSURL)

    The file URL that identifies the file you want to copy. The URL in this parameter must not be a file reference URL. This parameter must not be nil.

  • dstURL (NSURL)

    The URL at which to place the copy of srcURL. The URL in this parameter must not be a file reference URL and must include the name of the file in its new location. This parameter must not be nil.

  • error (Pointer)

    On input, a pointer to an error object. If an error occurs, this pointer is set to an actual error object containing the error information. You may specify nil for this parameter if you do not want the error information.

Returns:

  • (Boolean)

    YES if the item was copied successfully or the file manager’s delegate aborted the operation deliberately. Returns NO if an error occurred.

- (Boolean) createDirectoryAtPath(path, withIntermediateDirectories:createIntermediates, attributes:attributes, error:error)

Creates a directory with given attributes at the specified path. 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 directories 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.

Parameters:

  • path (String)

    A path string identifying the directory to create. You may specify a full path or a path that is relative to the current working directory. This parameter must not be nil.

  • createIntermediates (Boolean)

    If YES, this method creates any non-existent parent directories as part of creating the directory in url. If NO, this method fails if any of the intermediate parent directories does not exist. This method also fails if any of the intermediate path elements corresponds to a file and not a directory.

  • attributes (Hash)

    The file attributes for the new directory and any newly created intermediate directories. You can set the owner and group numbers, file permissions, and modification date. If you specify nil for this parameter or omit a particular value, one or more default values are used as described in the discussion. For a list of keys you can include in this dictionary, see “Constants” section lists the global constants used as keys in the attributes dictionary. Some of the keys, such as NSFileHFSCreatorCode and NSFileHFSTypeCode, do not apply to directories.

  • error (Pointer)

    On input, a pointer to an error object. If an error occurs, this pointer is set to an actual error object containing the error information. You may specify nil for this parameter if you do not want the error information.

Returns:

  • (Boolean)

    YES if the directory was created or already exists or NO if an error occurred.

- (Boolean) createDirectoryAtURL(url, withIntermediateDirectories:createIntermediates, attributes:attributes, error:error)

Creates a directory with the given attributes at the specified URL. 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 directories 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 you want to specify a relative path for url, you must set the current working directory before creating the corresponding NSURL object.

Parameters:

  • url (NSURL)

    A file URL that specifies the directory to create. If you want to specify a relative path, you must set the current working directory before creating the corresponding NSURL object. This parameter must not be nil.

  • createIntermediates (Boolean)

    If YES, this method creates any non-existent parent directories as part of creating the directory in url. If NO, this method fails if any of the intermediate parent directories does not exist.

  • attributes (Hash)

    The file attributes for the new directory. You can set the owner and group numbers, file permissions, and modification date. If you specify nil for this parameter, the directory is created according to the umask(2) OS X Developer Tools Manual Page of the process. The “Constants” section lists the global constants used as keys in the attributes dictionary. Some of the keys, such as NSFileHFSCreatorCode and NSFileHFSTypeCode, do not apply to directories.

  • error (Pointer)

    On input, a pointer to an error object. If an error occurs, this pointer is set to an actual error object containing the error information. You may specify nil for this parameter if you do not want the error information.

Returns:

  • (Boolean)

    YES if the directory was created or already exists or NO if an error occurred.

- (Boolean) createFileAtPath(path, contents:contents, attributes:attributes)

Creates a file with the specified content and attributes at the given location. 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.

Parameters:

  • path (String)

    The path for the new file.

  • contents (NSData)

    A data object containing the contents of the new file.

  • attributes (Hash)

    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 “File Attribute Keys.” If you specify nil for attributes, the file is created with a set of default attributes.

Returns:

  • (Boolean)

    YES if the operation was successful, otherwise NO.

- (Boolean) createSymbolicLinkAtPath(path, withDestinationPath:destPath, error:error)

Creates a symbolic link that points to the specified destination. This method does not traverse symbolic links contained in either path or destPath.

Parameters:

  • path (String)

    The path at which to create the new symbolic link. The last path component is used as the name of the link.

  • destPath (String)

    The path that contains the item to be pointed to by the link. In other words, this is the destination of the link.

  • error (Pointer)

    If an error occurs, upon return contains an NSError object that describes the problem. Pass NULL if you do not want error information.

Returns:

  • (Boolean)

    YES if the symbolic link was created or NO if an error occurred. This method also returns NO if a file, directory, or link already exists at path.

- (Boolean) createSymbolicLinkAtURL(url, withDestinationURL:destURL, error:error)

Creates a symbolic link at the specified URL that points to an item at the given URL. This method does not traverse symbolic links contained in either url or destURL.

Parameters:

  • url (NSURL)

    The file URL at which to create the new symbolic link. The last path component of the URL issued as the name of the link.

  • destURL (NSURL)

    The file URL that contains the item to be pointed to by the link. In other words, this is the destination of the link.

  • error (Pointer)

    On input, a pointer to an error object. If an error occurs, this pointer is set to an actual error object containing the error information. You may specify nil for this parameter if you do not want the error information.

Returns:

  • (Boolean)

    YES if the symbolic link was created or NO if an error occurred. This method also returns NO if a file, directory, or link already exists at path.

- (String) currentDirectoryPath

Returns the path of the program’s current directory. The string returned by this method is initialized to the current working directory; you can change the working directory by invoking changeCurrentDirectoryPath:. Relative pathnames refer implicitly to the current directory. For example, if the current directory is /tmp, and the relative pathname reports/info.txt is specified, the resulting full pathname is /tmp/reports/info.txt.

Returns:

  • (String)

    The path of the program’s current directory. If the program’s current working directory isn’t accessible, returns nil.

- (Object) delegate

Returns the delegate for the receiver.

Returns:

  • (Object)

    The delegate for the receiver.

- (String) destinationOfSymbolicLinkAtPath(path, error:error)

Returns the path of the item pointed to by a symbolic link.

Parameters:

  • path (String)

    The path of a file or directory.

  • error (Pointer)

    If an error occurs, upon return contains an NSError object that describes the problem. Pass NULL if you do not want error information.

Returns:

  • (String)

    An NSString object containing the path of the directory or file to which the symbolic link path refers, or nil upon failure. If the symbolic link is specified as a relative path, that relative path is returned.

- (String) displayNameAtPath(path)

Returns the display name of the file or directory at a specified path. Display names are user-friendly names for files. They are typically used to localize standard file and directory names according to the user’s language settings. They may also reflect other modifications, such as the removal of filename extensions. Such modifications are used only when displaying the file or directory to the user and do not reflect the actual path to the item in the file system. For example, if the current user’s preferred language is French, the following code fragment logs the name Bibliothèque and not the name Library, which is the actual name of the directory.

Parameters:

  • path (String)

    The path of a file or directory.

Returns:

  • (String)

    The name of the file or directory at path in a localized form appropriate for presentation to the user. If there is no file or directory at path, or if an error occurs, returns path as is.

- (NSDirectoryEnumerator) enumeratorAtPath(path)

Returns a directory enumerator object that can be used to perform a deep enumeration of the directory at the specified path. Because the enumeration is deep—that is, it lists the contents of all subdirectories—this enumerator object is useful for performing actions that involve large file-system subtrees. This method does not resolve symbolic links encountered in the traversal process, nor does it recurse through them if they point to a directory.This code fragment enumerates the subdirectories and files under a user’s Documents directory and processes all files with an extension of .doc: The NSDirectoryEnumerator class has methods for obtaining the attributes of the existing path and of the parent directory and for skipping descendants of the existing path.

Parameters:

  • path (String)

    The path of the directory to enumerate.

Returns:

  • (NSDirectoryEnumerator)

    An NSDirectoryEnumerator object that enumerates the contents of the directory at path.If path is a filename, the method returns an enumerator object that enumerates no files—the first call to nextObject will return nil.

- (NSDirectoryEnumerator) enumeratorAtURL(url, includingPropertiesForKeys:keys, options:mask, errorHandler:handler)

Returns a directory enumerator object that can be used to perform a deep enumeration of the directory at the specified URL. Because the enumeration is deep—that is, it lists the contents of all subdirectories—this enumerator object is useful for performing actions that involve large file-system subtrees. If the method is passed a directory on which another file system is mounted (a mount point), it traverses the mount point. This method does not resolve symbolic links encountered in the traversal process, nor does it recurse through them if they point to a directory.The NSDirectoryEnumerator class has methods for skipping descendants of the existing path and for returning the number of levels deep the current object is in the directory hierarchy being enumerated (where the directory passed to enumeratorAtURL:includingPropertiesForKeys:options:errorHandler: is considered to be level 0).This code fragment enumerates a URL and it’s subdirectories, collecting the URLs of files (skips directories). It also demonstrates how to ignore the contents of specified directories, in this case directories named “_extras”.

Parameters:

  • url

    The location of the directory for which you want an enumeration. This URL must not be a symbolic link that points to the desired directory. You can use the URLByResolvingSymlinksInPath method to resolve any symlinks in the URL.

  • keys

    An array of keys that identify the properties that you want pre-fetched for each item in the enumeration. The values for these keys are cached in the corresponding NSURL objects. You may specify nil for this parameter. For a list of keys you can specify, see Common File System Resource Keys.

  • mask

    Options for the enumeration. For a list of valid options, see “Directory Enumeration Options.”

  • handler

    An optional ‘errorHandler’ block argument to call when an error occurs. The url parameter specifies the item for which the error occurred and the error parameter contains the error information. Your handler should return YES when it wants the enumeration to continue or NO when it wants the enumeration to stop.

Returns:

  • (NSDirectoryEnumerator)

    An NSDirectoryEnumerator object that enumerates the contents of the directory at url. If url is a filename, the method returns an enumerator object that enumerates no files—the first call to nextObject returns nil.

- (Boolean) evictUbiquitousItemAtURL(url, error:errorOut)

Removes the local copy of the specified cloud-based item. This method does not remove the item from the cloud. It removes only the local version. You can use this method to force iCloud to download a new version of the file or directory from the server. To delete a file permanently from the user’s iCloud storage, use the regular NSFileManager routines for deleting files and directories. Remember that deleting items from iCloud cannot be undone. Once deleted, the item is gone forever.

Parameters:

  • url (NSURL)

    Specify the URL to a file or directory in iCloud storage.

  • errorOut (Pointer)

    On input, a pointer to variable for an NSError object. If an error occurs, this pointer is set to an NSError object containing information about the error. You may specify nil for this parameter if you do not want the error information.

Returns:

  • (Boolean)

    YES if the local item was removed successfully or NO if it was not. If NO is returned and errorOut is not nil, an NSError object describing the error is returned in that parameter.

- (Boolean) fileExistsAtPath(path)

Returns a Boolean value that indicates whether a file or directory exists at a specified path. If the file at path is inaccessible to your app, perhaps because one or more parent directories are inaccessible, this method returns NO. If the final element in path specifies a symbolic link, this method traverses the link and returns YES or NO based on the existence of the file at the link destination. Note: Attempting to predicate behavior based on the current state of the file system or a particular file on the file system is not recommended. Doing so can cause odd behavior or race conditions. It’s far better to attempt an operation (such as loading a file or creating a directory), check for errors, and handle those errors gracefully than it is to try to figure out ahead of time whether the operation will succeed. For more information on file system race conditions, see “Race Conditions and Secure File Operations” in Secure Coding Guide.

Parameters:

  • path (String)

    The path of the file or directory. If path begins with a tilde (~), it must first be expanded with stringByExpandingTildeInPath, otherwise, this method returns NO.

Returns:

  • (Boolean)

    YES if a file at the specified path exists or NO if the file’s does not exist or its existence could not be determined.

- (Boolean) fileExistsAtPath(path, isDirectory:isDirectory)

Returns a Boolean value that indicates whether a file or directory exists at a specified path. If the file at path is inaccessible to your app, perhaps because one or more parent directories are inaccessible, this method returns NO. If the final element in path specifies a symbolic link, this method traverses the link and returns YES or NO based on the existence of the file at the link destination. If you need to further determine if path is a package, use the isFilePackageAtPath: method of NSWorkspace.This example gets an array that identifies the fonts in the user’s fonts directory: Note: Attempting to predicate behavior based on the current state of the file system or a particular file on the file system is not recommended. Doing so can cause odd behavior or race conditions. It’s far better to attempt an operation (such as loading a file or creating a directory), check for errors, and handle those errors gracefully than it is to try to figure out ahead of time whether the operation will succeed. For more information on file system race conditions, see “Race Conditions and Secure File Operations” in Secure Coding Guide.

Parameters:

  • path (String)

    The path of a file or directory. If path begins with a tilde (~), it must first be expanded with stringByExpandingTildeInPath, or this method will return NO.

  • isDirectory (Boolean)

    Upon return, contains YES if path is a directory or if the final path element is a symbolic link that points to a directory, otherwise contains NO. If path doesn’t exist, the return value is undefined. Pass NULL if you do not need this information.

Returns:

  • (Boolean)

    YES if a file at the specified path exists or NO if the file’s does not exist or its existence could not be determined.

- (const char) fileSystemRepresentationWithPath(path)

Returns a C-string representation of a given path that properly encodes Unicode strings for use by the file system. Use this method if your code calls system routines that expect C-string path arguments. If you use the C string beyond the scope of the current autorelease pool, you must copy it. This method raises an exception if path is nil or contains the empty string. This method also throws an exception if the conversion of the string fails.

Parameters:

  • path (String)

    A string object containing a path to a file. This parameter must not be nil or contain the empty string.

Returns:

  • (const char)

    A C-string representation of path that properly encodes Unicode strings for use by the file system.

- (Object) init

Returns an initialized NSFileManager instance. In iOS and in OS X 10.5 and later you can use this method to create a specific file manager instance. You might do this in situations where you want to associate a delegate with the file manager to receive notifications about the status of file-related operations.

Returns:

- (Boolean) isDeletableFileAtPath(path)

Returns a Boolean value that indicates whether the invoking object appears able to delete a specified file. For a directory or file to be deletable, the current process must either be able to write to the parent directory of path or it must have the same owner as the item at path. If path is a directory, every item contained in path must be deletable by the current process.If the file at path is inaccessible to your app, perhaps because it does not have search privileges for one or more parent directories, this method returns NO. This method does not traverse symbolic links in the path.Note: Attempting to predicate behavior based on the current state of the file system or a particular file on the file system is not recommended. Doing so can cause odd behavior or race conditions. It’s far better to attempt an operation (such as loading a file or creating a directory), check for errors, and handle those errors gracefully than it is to try to figure out ahead of time whether the operation will succeed. For more information on file system race conditions, see “Race Conditions and Secure File Operations” in Secure Coding Guide.

Parameters:

  • path (String)

    A file path.

Returns:

  • (Boolean)

    YES if the current process has delete privileges for the file at path; otherwise NO if the process does not have delete privileges or the existence of the file could not be determined.

- (Boolean) isExecutableFileAtPath(path)

Returns a Boolean value that indicates whether the operating system appears able to execute a specified file. If the file at path is inaccessible to your app, perhaps because it does not have search privileges for one or more parent directories, this method returns NO. This method traverses symbolic links in the path. This method also uses the real user ID and group ID, as opposed to the effective user and group IDs, to determine if the file is executable. Note: Attempting to predicate behavior based on the current state of the file system or a particular file on the file system is not recommended. Doing so can cause odd behavior or race conditions. It’s far better to attempt an operation (such as loading a file or creating a directory), check for errors, and handle those errors gracefully than it is to try to figure out ahead of time whether the operation will succeed. For more information on file system race conditions, see “Race Conditions and Secure File Operations” in Secure Coding Guide.

Parameters:

  • path (String)

    A file path.

Returns:

  • (Boolean)

    YES if the current process has execute privileges for the file at path; otherwise NO if the process does not have execute privileges or the existence of the file could not be determined.

- (Boolean) isReadableFileAtPath(path)

Returns a Boolean value that indicates whether the invoking object appears able to read a specified file. If the file at path is inaccessible to your app, perhaps because it does not have search privileges for one or more parent directories, this method returns NO. This method traverses symbolic links in the path. This method also uses the real user ID and group ID, as opposed to the effective user and group IDs, to determine if the file is readable. Note: Attempting to predicate behavior based on the current state of the file system or a particular file on the file system is not recommended. Doing so can cause odd behavior or race conditions. It’s far better to attempt an operation (such as loading a file or creating a directory), check for errors, and handle those errors gracefully than it is to try to figure out ahead of time whether the operation will succeed. For more information on file system race conditions, see “Race Conditions and Secure File Operations” in Secure Coding Guide.

Parameters:

  • path (String)

    A file path.

Returns:

  • (Boolean)

    YES if the current process has read privileges for the file at path; otherwise NO if the process does not have read privileges or the existence of the file could not be determined.

- (Boolean) isUbiquitousItemAtURL(url)

Returns a Boolean indicating whether the item is targeted for storage in iCloud. This method reflects only whether the item should be stored in iCloud because a call was made to the setUbiquitous:itemAtURL:destinationURL:error: method with a value of YES for its flag parameter. This method does not reflect whether the file has actually been uploaded to any iCloud servers. To determine a file’s upload status, check the NSURLUbiquitousItemIsUploadedKey attribute of the corresponding NSURL object.

Parameters:

  • url (NSURL)

    Specify the URL for the file or directory whose status you want to check.

Returns:

  • (Boolean)

    YES if the item is targeted for iCloud storage or NO if it is not. This method also returns NO if no item exists at url.

- (Boolean) isWritableFileAtPath(path)

Returns a Boolean value that indicates whether the invoking object appears able to write to a specified file. If the file at path is inaccessible to your app, perhaps because it does not have search privileges for one or more parent directories, this method returns NO. This method traverses symbolic links in the path. This method also uses the real user ID and group ID, as opposed to the effective user and group IDs, to determine if the file is writable. Note: Attempting to predicate behavior based on the current state of the file system or a particular file on the file system is not recommended. Doing so can cause odd behavior or race conditions. It’s far better to attempt an operation (such as loading a file or creating a directory), check for errors, and handle those errors gracefully than it is to try to figure out ahead of time whether the operation will succeed. For more information on file system race conditions, see “Race Conditions and Secure File Operations” in Secure Coding Guide.

Parameters:

  • path (String)

    A file path.

Returns:

  • (Boolean)

    YES if the current process has write privileges for the file at path; otherwise NO if the process does not have write privileges or the existence of the file could not be determined.

- (Boolean) linkItemAtPath(srcPath, toPath:dstPath, error:error)

Creates a hard link between the items at the specified paths. Use this method to create hard links between files in the current file system. If dstPath is a directory, this method creates a new directory at srcPath and then creates hard links for the items in that directory. If dstPath is (or contains) a symbolic link, the symbolic link is copied to the new location and not converted to a hard link.Prior to linking each item, the file manager asks its delegate if it should actually create the link. It does this by calling the fileManager:shouldLinkItemAtURL:toURL: method; if that method is not implemented it calls the fileManager:shouldLinkItemAtPath:toPath: method instead. If the delegate method returns YES, or if the delegate does not implement the appropriate methods, the file manager creates the hard link. If there is an error moving one out of several items, the file manager may also call the delegate’s fileManager:shouldProceedAfterError:linkingItemAtURL:toURL: or fileManager:shouldProceedAfterError:linkingItemAtPath:toPath: method to determine how to proceed.

Parameters:

  • srcPath (String)

    The path that specifies where you want to create the hard link. The value in this parameter must not be nil.

  • dstPath (String)

    The path that identifies the destination of the link. The value in this parameter must not be nil.

  • error (Pointer)

    On input, a pointer to an error object. If an error occurs, this pointer is set to an actual error object containing the error information. You may specify nil for this parameter if you do not want the error information.

Returns:

  • (Boolean)

    YES if the hard link was created or NO if an error occurred. This method also returns NO if a file, directory, or link already exists at path.

- (Boolean) linkItemAtURL(srcURL, toURL:dstURL, error:error)

Creates a hard link between the items at the specified URLs. Use this method to create hard links between files in the current file system. If dstURL is a directory, this method creates a new directory at srcURL and then creates hard links for the items in that directory. If dstURL is (or contains) a symbolic link, the symbolic link is copied and not converted to a hard link at srcURL.Prior to linking each item, the file manager asks its delegate if it should actually create the link. It does this by calling the fileManager:shouldLinkItemAtURL:toURL: method; if that method is not implemented it calls the fileManager:shouldLinkItemAtPath:toPath: method instead. If the delegate method returns YES, or if the delegate does not implement the appropriate methods, the file manager creates the hard link. If there is an error moving one out of several items, the file manager may also call the delegate’s fileManager:shouldProceedAfterError:linkingItemAtURL:toURL: or fileManager:shouldProceedAfterError:linkingItemAtPath:toPath: method to determine how to proceed.

Parameters:

  • srcURL (NSURL)

    The file URL that identifies the destination of the link. The URL in this parameter must not be a file reference URL; it must specify the actual path to the item. The value in this parameter must not be nil.

  • dstURL (NSURL)

    The file URL that specifies where you want to create the hard link. The URL in this parameter must not be a file reference URL; it must specify the actual path to the item. The value in this parameter must not be nil.

  • error (Pointer)

    On input, a pointer to an error object. If an error occurs, this pointer is set to an actual error object containing the error information. You may specify nil for this parameter if you do not want the error information.

Returns:

  • (Boolean)

    YES if the hard link was created or NO if an error occurred. This method also returns NO if a file, directory, or link already exists at path.

- (Array) mountedVolumeURLsIncludingResourceValuesForKeys(propertyKeys, options:options)

Returns an array of URLs that identify the mounted volumes available on the computer. This call may block if I/O is required to determine values for the requested propertyKeys.

Parameters:

  • propertyKeys (Array)

    An array of keys that identify the file properties that you want pre-fetched for each volume. For each returned URL, the values for these keys are cached in the corresponding NSURL objects. You may specify nil for this parameter. For a list of keys you can specify, see Common File System Resource Keys.

  • options (NSVolumeEnumerationOptions)

    Option flags for the enumeration. See “Mounted Volume Enumeration Options.”

Returns:

  • (Array)

    An array of NSURL objects identifying the mounted volumes.

- (Boolean) moveItemAtPath(srcPath, toPath:dstPath, error:error)

Moves the file or directory at the specified path to a new location synchronously. When moving items, the current process must have permission to read the item at srcPath and write the parent directory of dstPath. If the item at srcPath is a directory, this method moves the directory and all of its contents, including any hidden files. If an item with the same name already exists at dstPath, this method aborts the move attempt and returns an appropriate error. If the last component of srcPath is a symbolic link, only the link is moved to the new path; the item pointed to by the link remains at its current location.Prior to moving the item, the file manager asks its delegate if it should actually move it. It does this by calling the fileManager:shouldMoveItemAtURL:toURL: method; if that method is not implemented it calls the fileManager:shouldMoveItemAtPath:toPath: method instead. If the item being moved is a directory, the file manager notifies the delegate only for the directory itself and not for any of its contents. If the delegate method returns YES, or if the delegate does not implement the appropriate methods, the file manager moves the file. If there is an error moving one out of several items, the file manager may also call the delegate’s fileManager:shouldProceedAfterError:movingItemAtURL:toURL: or fileManager:shouldProceedAfterError:movingItemAtPath:toPath: method to determine how to proceed.If the source and destination of the move operation are not on the same volume, this method copies the item first and then removes it from its current location. This behavior may trigger additional delegate notifications related to copying and removing individual items.

Parameters:

  • srcPath (String)

    The path to the file or directory you want to move. This parameter must not be nil.

  • dstPath (String)

    The new path for the item in srcPath. This path must include the name of the file or directory in its new location. This parameter must not be nil.

  • error (Pointer)

    On input, a pointer to an error object. If an error occurs, this pointer is set to an actual error object containing the error information. You may specify nil for this parameter if you do not want the error information.

Returns:

  • (Boolean)

    YES if the item was moved successfully or the file manager’s delegate aborted the operation deliberately. Returns NO if an error occurred.

- (Boolean) moveItemAtURL(srcURL, toURL:dstURL, error:error)

Moves the file or directory at the specified URL to a new location synchronously. When moving items, the current process must have permission to read the item at srcURL and write the parent directory of dstURL. If the item at srcURL is a directory, this method moves the directory and all of its contents, including any hidden files. If an item with the same name already exists at dstURL, this method aborts the move attempt and returns an appropriate error. If the last component of srcURL is a symbolic link, only the link is moved to the new path; the item pointed to by the link remains at its current location.Prior to moving the item, the file manager asks its delegate if it should actually move it. It does this by calling the fileManager:shouldMoveItemAtURL:toURL: method; if that method is not implemented it calls the fileManager:shouldMoveItemAtPath:toPath: method instead. If the item being moved is a directory, the file manager notifies the delegate only for the directory itself and not for any of its contents. If the delegate method returns YES, or if the delegate does not implement the appropriate methods, the file manager moves the file. If there is an error moving one out of several items, the file manager may also call the delegate’s fileManager:shouldProceedAfterError:movingItemAtURL:toURL: or fileManager:shouldProceedAfterError:movingItemAtPath:toPath: method to determine how to proceed.If the source and destination of the move operation are not on the same volume, this method copies the item first and then removes it from its current location. This behavior may trigger additional delegate notifications related to copying and removing individual items.

Parameters:

  • srcURL (NSURL)

    The file URL that identifies the file or directory you want to move. The URL in this parameter must not be a file reference URL. This parameter must not be nil.

  • dstURL (NSURL)

    The new location for the item in srcURL. The URL in this parameter must not be a file reference URL and must include the name of the file or directory in its new location. This parameter must not be nil.

  • error (Pointer)

    On input, a pointer to an error object. If an error occurs, this pointer is set to an actual error object containing the error information. You may specify nil for this parameter if you do not want the error information.

Returns:

  • (Boolean)

    YES if the item was moved successfully or the file manager’s delegate aborted the operation deliberately. Returns NO if an error occurred.

- (Boolean) removeItemAtPath(path, error:error)

Removes the file or directory at the specified path. Prior to removing each item, the file manager asks its delegate if it should actually do so. It does this by calling the fileManager:shouldRemoveItemAtURL: method; if that method is not implemented (or the process is running in OS X 10.5 or earlier) it calls the fileManager:shouldRemoveItemAtPath: method instead. If the delegate method returns YES, or if the delegate does not implement the appropriate methods, the file manager proceeds to remove the file or directory. If there is an error removing an item, the file manager may also call the delegate’s fileManager:shouldProceedAfterError:removingItemAtURL: or fileManager:shouldProceedAfterError:removingItemAtPath: method to determine how to proceed.

Parameters:

  • path (String)

    A path string indicating the file or directory to remove. If the path specifies a directory, the contents of that directory are recursively removed. You may specify nil for this parameter.

  • error (Pointer)

    On input, a pointer to an error object. If an error occurs, this pointer is set to an actual error object containing the error information. You may specify nil for this parameter if you do not want the error information.

Returns:

  • (Boolean)

    YES if the item was removed successfully or if path was nil. Returns NO if an error occurred. If the delegate aborts the operation for a file, this method returns YES. However, if the delegate aborts the operation for a directory, this method returns NO.

- (Boolean) removeItemAtURL(URL, error:error)

Removes the file or directory at the specified URL. Prior to removing each item, the file manager asks its delegate if it should actually do so. It does this by calling the fileManager:shouldRemoveItemAtURL: method; if that method is not implemented (or the process is running in OS X 10.5 or earlier) it calls the fileManager:shouldRemoveItemAtPath: method instead. If the delegate method returns YES, or if the delegate does not implement the appropriate methods, the file manager proceeds to remove the file or directory. If there is an error removing an item, the file manager may also call the delegate’s fileManager:shouldProceedAfterError:removingItemAtURL: or fileManager:shouldProceedAfterError:removingItemAtPath: method to determine how to proceed.

Parameters:

  • URL (NSURL)

    A file URL specifying the file or directory to remove. If the URL specifies a directory, the contents of that directory are recursively removed. You may specify nil for this parameter.

  • error (Pointer)

    On input, a pointer to an error object. If an error occurs, this pointer is set to an actual error object containing the error information. You may specify nil for this parameter if you do not want the error information.

Returns:

  • (Boolean)

    YES if the item was removed successfully or if URL was nil. Returns NO if an error occurred. If the delegate aborts the operation for a file, this method returns YES. However, if the delegate aborts the operation for a directory, this method returns NO.

- (Boolean) replaceItemAtURL(originalItemURL, withItemAtURL:newItemURL, backupItemName:backupItemName, options:options, resultingItemURL:resultingURL, error:error)

Replaces the contents of the item at the specified URL in a manner that insures no data loss occurs. By default, the creation date, permissions, Finder label and color, and Spotlight comments of the original item will be preserved on the resulting item.If an error occurs and the original item is not in the original location or a temporary location, the returned error object contains a user info dictionary with the NSFileOriginalItemLocationKey key. The value assigned to that key is an NSURL object with the location of the item. The error code is one of the file-related errors described in NSError Codes.

Parameters:

  • originalItemURL (NSURL)

    The item whose contents you want to replace.

  • newItemURL (NSURL)

    The item containing the new content for originalItemURL. It is recommended that you put this item in a temporary directory as provided by the OS. If a temporary directory is not available, put this item in a uniquely named directory that is in the same directory as the original item.

  • backupItemName (String)

    Optional. If provided, this name is used to create a backup of the original item.The backup is placed in the same directory as the original item. If an error occurs during the creation of the backup item, the operation will fail. If there is already an item with the same name as the backup item, that item will be removed.The backup item will be removed in the event of success unless the NSFileManagerItemReplacementWithoutDeletingBackupItem option is provided in options.

  • options (NSFileManagerItemReplacementOptions)

    Specifies the options to use during the replacement. Typically, you pass 0 for this parameter, which uses only the metadata from the new item. You can also combine the options described in “NSFileManagerItemReplacementOptions” using the C-bitwise OR operator.

  • resultingURL (Pointer)

    On input, a pointer for a URL object. When the item is replaced, this pointer is set to the URL of the new item. If no new file system object is required, the URL object in this parameter may be the same passed to the originalItemURL parameter. However, if a new file system object is required, the URL object may be different. For example, replacing an RTF document with an RTFD document requires the creation of a new file.

  • error (Pointer)

    On input, a pointer to an error object. If an error occurs, this pointer is set to an actual error object containing the error information. You may specify nil for this parameter if you do not want the error information.

Returns:

  • (Boolean)

    YES if the replacement was successful or NO if an error occurred.

- (Boolean) setAttributes(attributes, ofItemAtPath:path, error:error)

Sets the attributes of the specified file or directory. As in the POSIX standard, the app either must own the file or directory or must be running as superuser for attribute changes to take effect. The method attempts to make all changes specified in attributes and ignores any rejection of an attempted modification. If the last component of the path is a symbolic link it is traversed.The NSFilePosixPermissions value must be initialized with the code representing the POSIX file-permissions bit pattern. NSFileHFSCreatorCode and NSFileHFSTypeCode will only be heeded when path specifies a file.

Parameters:

  • attributes (Hash)

    A dictionary containing as keys the attributes to set for path and as values the corresponding value for the attribute. You can set the following attributes: NSFileBusy, NSFileCreationDate, NSFileExtensionHidden, NSFileGroupOwnerAccountID, NSFileGroupOwnerAccountName, NSFileHFSCreatorCode, NSFileHFSTypeCode, NSFileImmutable, NSFileModificationDate, NSFileOwnerAccountID, NSFileOwnerAccountName, NSFilePosixPermissions. You can change single attributes or any combination of attributes; you need not specify keys for all attributes.

  • path (String)

    The path of a file or directory.

  • error (Pointer)

    On input, a pointer to an error object. If an error occurs, this pointer is set to an actual error object containing the error information. You may specify nil for this parameter if you do not want the error information.

Returns:

  • (Boolean)

    YES if all changes succeed. If any change fails, returns NO, but it is undefined whether any changes actually occurred.

- (Object) setDelegate(delegate)

Sets the delegate for the receiver. It is recommended that you assign a delegate only to file manager objects that you create explicitly using the alloc/init convention.

Parameters:

Returns:

- (Boolean) setUbiquitous(flag, itemAtURL:url, destinationURL:destinationURL, error:errorOut)

Sets whether the item at the specified URL should be stored in the cloud. Use this method to move a file from its current location to iCloud. For files located in an app’s sandbox, this involves physically removing the file from the sandbox container. (The system extends your app’s sandbox privileges to give it access to files it moves to iCloud.) You can also use this method to move files out of iCloud and back into a local directory.Your app must have an active file presenter object configured to monitor the specified file or directory before calling this method. When you specify YES for the flag parameter, this method attempts to move the file or directory to the cloud and returns YES if it is successful. This method also notifies your file presenter of the new location of the file so that your app can continue to operate on it.Important: Do not call this method from your app’s main thread. This method performs a coordinated write operation on the file you specify, and calling this method from the main thread can trigger a deadlock with the file presenter you have monitoring the file. Instead, use a dispatch queue (other than the main thread queue) to call this method from a secondary thread. You can message your main thread after the call finishes to update the rest of your app’s data structures.

Parameters:

  • flag (Boolean)

    Specify YES to move the item to iCloud or NO to remove it from iCloud (if it is there currently).

  • url (NSURL)

    Specify the URL of the item (file or directory) that you want to store in iCloud.

  • destinationURL (NSURL)

    Specify the location in iCloud at which to store the file or directory. This URL must be constructed from a URL returned by the URLForUbiquityContainerIdentifier: method, which you use to retrieve the desired iCloud container directory. The URL you specify may contain additional subdirectories so that you can organize your files hierarchically in iCloud. However, you are responsible for creating those intermediate subdirectories (using the NSFileManager class) in your iCloud container directory.

  • errorOut (Pointer)

    On input, a pointer to variable for an NSError object. If an error occurs, this pointer is set to an NSError object containing information about the error. You may specify nil for this parameter if you do not want the error information.

Returns:

  • (Boolean)

    YES if the item’s status was updated successfully or NO if an error occurred. If this method returns NO and you specified a value for the errorOut parameter, this method returns an error object in the provided pointer.

- (Boolean) startDownloadingUbiquitousItemAtURL(url, error:errorOut)

Starts downloading (if necessary) the specified item to the local system. If a cloud-based file or directory has not been downloaded yet, calling this method starts the download process. If the item exists locally, calling this method synchronizes the local copy with the version in the cloud. For a given URL, you can determine if a file is downloaded by getting the value of the NSMetadataUbiquitousItemIsDownloadedKey key. You can also use related keys to determine the current progress in downloading the file.

Parameters:

  • url (NSURL)

    Specify the URL for the file or directory in the cloud that you want to download.

  • errorOut (Pointer)

    On input, a pointer to variable for an NSError object. If an error occurs, this pointer is set to an NSError object containing information about the error. You may specify nil for this parameter if you do not want the error information.

Returns:

  • (Boolean)

    YES if the download started successfully or was not necessary, otherwise NO. If NO is returned and errorOut is not nil, an NSError object describing the error is returned in that parameter.

- (String) stringWithFileSystemRepresentation(string, length:len)

Returns an NSString object whose contents are derived from the specified C-string path. Use this method if your code receives paths as C strings from system routines.

Parameters:

  • string (const char)

    A C string representation of a pathname.

  • len (Integer)

    The number of characters in string.

Returns:

  • (String)

    An NSString object converted from the C-string representation string with length len of a pathname in the current file system.

- (Array) subpathsAtPath(path)

Returns an array of strings identifying the paths for all items in the specified directory. This method recurses the specified directory and its subdirectories. The method skips the “.” and “..” directories at each level of the recursion.This method reveals every element of the subtree at path, including the contents of file packages (such as apps, nib files, and RTFD files). This code fragment gets the contents of /System/Library/Fonts after verifying that the directory exists:

Parameters:

  • path (String)

    The path of the directory to list.

Returns:

  • (Array)

    An array of NSString objects, each of which contains the path of an item in the directory specified by path. If path is a symbolic link, this method traverses the link. This method returns nil if it cannot retrieve the device of the linked-to file.

- (Array) subpathsOfDirectoryAtPath(path, error:error)

Performs a deep enumeration of the specified directory and returns the paths of all of the contained subdirectories. This method recurses the specified directory and its subdirectories. The method skips the “.” and “..” directories at each level of the recursion.Because this method recurses the directory’s contents, you might not want to use it in performance-critical code. Instead, consider using the enumeratorAtURL:includingPropertiesForKeys:options:errorHandler: or enumeratorAtPath: method to enumerate the directory contents yourself. Doing so gives you more control over the retrieval of items and more opportunities to abort the enumeration or perform other tasks at the same time.

Parameters:

  • path (String)

    The path of the directory to list.

  • error (Pointer)

    If an error occurs, upon return contains an NSError object that describes the problem. Pass NULL if you do not want error information.

Returns:

  • (Array)

    An array of NSString objects, each of which contains the path of an item in the directory specified by path. If path is a symbolic link, this method traverses the link. This method returns nil if it cannot retrieve the device of the linked-to file.

- (Object) ubiquityIdentityToken

Returns an opaque token that represents the current iCloud (“ubiquity”) identity. Call this method to check if iCloud is available. You can call this method on the main thread.You can also use this method, together with the NSUbiquityIdentityDidChangeNotification notification, to detect when a user changes to a different iCloud account, or logs in or out of iCloud. When the ubiquity identity changes, the system posts that notification.You can copy or encode a ubiquity identity token, and you can compare it to previously-obtained values by using the isEqual: method.This method returns nil if ubiquity containers are unavailable because the user has disabled them, or if the user is not logged in to iCloud.Calling this method does not establish access to your app’s ubiquity containers. To establish access to a ubiquity container, call the URLForUbiquityContainerIdentifier: method. In OS X, you can instead use an NSDocument object, which establishes access automatically.

Returns:

- (NSURL) URLForDirectory(directory, inDomain:domain, appropriateForURL:url, create:shouldCreate, error:error)

Locates and optionally creates the specified common directory in a domain. You typically use this method to locate one of the standard system directories, such as the Documents, Application Support or Caches directories. You can also use this method to create a new temporary directory for storing things like autosave files; to do so, specify NSItemReplacementDirectory for the directory parameter, NSUserDomainMask for the domain parameter, and a valid parent directory for the url parameter. After locating (or creating) the desired directory, this method returns the URL for that directory. If more than one appropriate directory exists in the specified domain, this method returns only the first one it finds.Passing a directory and domain pair that makes no sense (for example NSDesktopDirectory and NSNetworkDomainMask) raises an exception.

Parameters:

  • directory (NSSearchPathDirectory)

    The search path directory. The supported values are described in NSSearchPathDirectory.

  • domain (NSSearchPathDomainMask)

    The file system domain to search. The value for this parameter is one of the constants described in NSSearchPathDomainMask. You should specify only one domain for your search and you may not specify the NSAllDomainsMask constant for this parameter.

  • url (NSURL)

    The name of a directory inside of which you want to create a unique temporary directory for autosaving documents or some other use. This parameter is ignored unless the directory parameter contains the value NSItemReplacementDirectory and the domain parameter contains the value NSUserDomainMask. When creating a temporary directory, the shouldCreate parameter is ignored and the directory is always created.

  • shouldCreate (Boolean)

    Specify YES if you want the directory to be created if it does not exist.

  • error (Pointer)

    On input, a pointer to an error object. If an error occurs, this pointer is set to an actual error object containing the error information. You may specify nil for this parameter if you do not want the error information.

Returns:

  • (NSURL)

    The NSURL for the requested directory or nil if an error occurred.

- (NSURL) URLForPublishingUbiquitousItemAtURL(url, expirationDate:outDate, error:error)

Returns a URL that can be emailed to users to allow them to download a copy of a cloud-based item. This method creates a snapshot of the specified file and places that copy in a temporary iCloud location where it can be accessed by other users using the returned URL. The snapshot reflects the contents of the file at the time the URL was generated and is not updated when subsequent changes are made to the original file in the user’s iCloud storage. The snapshot file remains available at the specified URL until the date specified in the outDate parameter, after which it is automatically deleted. Your app must have access to the network for this call to succeed.

Parameters:

  • url (NSURL)

    Specify the URL of the item in the cloud that you want to share. The URL must be prefixed with the base URL returned from the URLForUbiquityContainerIdentifier: method that corresponds to the item’s location.

  • outDate (Pointer)

    On input, a pointer to a variable for a date object. On output, this parameter contains the date after which the item is no longer available at the returned URL. You may specify nil for this parameter if you are not interested in the date.

  • error (Pointer)

    On input, a pointer to variable for an NSError object. If an error occurs, this pointer is set to an NSError object containing information about the error. You may specify nil for this parameter if you do not want the error information.

Returns:

  • (NSURL)

    A URL with which users can download a copy of the item at url. Returns nil if the URL could not be created for any reason.

- (NSURL) URLForUbiquityContainerIdentifier(containerID)

Returns the URL for the ubiquity (iCloud) container associated with the specified container identifier, and establishes access to that container. In OS X, you do not need to call this method if you use NSDocument-based objects, because the system then calls this method automatically.You can use the URL returned by this method to build paths to files and directories within your app’s ubiquity container. Each app that syncs documents to the cloud must have at least one associated ubiquity container in which to put those files. This container can be unique to the app or shared by multiple apps.Important: Do not call this method from your app’s main thread. Instead, use a dispatch queue (other than the main thread queue) to call this method from a secondary thread. In addition to writing to its own ubiquity container, an app can write to any container directory for which it has the appropriate permission. Each additional ubiquity container should be listed as an additional value in the com.apple.developer.ubiquity-container-identifiers entitlement array. To learn how to view your development team’s unique value, read “To view the team ID…” in Tools Workflow Guide for Mac.Note: The development team ID that precedes each container ID string is the unique identifier associated with your development team. To learn how to view your development team’s unique value, read “To view the team ID…” in Tools Workflow Guide for Mac.The first time you call this method for a given ubiquity container, the system extends your app’s sandbox to include that container. In iOS, you must call this method at least once before trying to search for cloud-based files in the ubiquity container. If your app accesses multiple ubiquity containers, call this method once for each container.

Parameters:

  • containerID (String)

    The fully-qualified container identifier for a ubiquity container. The string you specify must not contain wildcards and must be of the form ., where is your development team ID and describes the bundle identifier of the container you want to access.The container identifiers for your app must be declared in the com.apple.developer.ubiquity-container-identifiers array of the .entitlements property list file in your Xcode project.If you specify nil in this parameter, this method returns the first container listed in the com.apple.developer.ubiquity-container-identifiers entitlement array.

Returns:

  • (NSURL)

    A URL pointing to the specified ubiquity container, or nil if the container could not be located or if iCloud storage is unavailable for the current user or device.

- (Array) URLsForDirectory(directory, inDomains:domainMask)

Returns an array of URLs for the specified common directory in the requested domains. This method is intended to locate known and common directories in the system. For example, setting the directory to NSApplicationDirectory, will return the Applications directories in the requested domain. There are a number of common directories available in the NSSearchPathDirectory, including: NSDesktopDirectory, NSApplicationSupportDirectory, and many more.

Parameters:

  • directory (NSSearchPathDirectory)

    The search path directory. The supported values are described in NSSearchPathDirectory.

  • domainMask (NSSearchPathDomainMask)

    The file system domain to search. The value for this parameter is one or more of the constants described in NSSearchPathDomainMask.

Returns:

  • (Array)

    An array of NSURL objects identifying the requested directories. The directories are ordered according to the order of the domain mask constants, with items in the user domain first and items in the system domain last.