iOS Developer Library — Pre-Release

Developer

Foundation Framework Reference NSFileManager Class Reference

Options
Deployment Target:

On This Page
Language:

NSFileManager

An NSFileManager object lets you examine the contents of the file system and make changes to it. A file manager object is usually your first interaction with the file system. You use it to locate, create, copy, and move files and directories. You also use it to get information about a file or directory or change some of its attributes. More...

Inheritance


Conforms To


Import Statement


Swift

import Foundation

Objective-C

@import Foundation;

Availability


Available in iOS 2.0 and later.
  • Returns an initialized NSFileManager instance.

    Declaration

    Objective-C

    init

    Return Value

    An initialized NSFileManager instance.

    Discussion

    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 the shared file manager object for the process.

    Declaration

    Swift

    class func defaultManager() -> NSFileManager

    Objective-C

    + (NSFileManager *)defaultManager

    Return Value

    The default NSFileManager object for the file system.

    Discussion

    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.

    Import Statement

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • Locates and optionally creates the specified common directory in a domain.

    Declaration

    Swift

    func URLForDirectory(_ directory: NSSearchPathDirectory, inDomain domain: NSSearchPathDomainMask, appropriateForURL url: NSURL?, create shouldCreate: Bool, error error: NSErrorPointer) -> NSURL?

    Objective-C

    - (NSURL *)URLForDirectory:(NSSearchPathDirectory)directory inDomain:(NSSearchPathDomainMask)domain appropriateForURL:(NSURL *)url create:(BOOL)shouldCreate error:(NSError **)error

    Parameters

    directory

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

    domain

    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

    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

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

    error

    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.

    Return Value

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

    Discussion

    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.

    Import Statement

    Swift

    import Foundation

    Availability

    Available in iOS 4.0 and later.

  • Returns an array of URLs for the specified common directory in the requested domains.

    Declaration

    Swift

    func URLsForDirectory(_ directory: NSSearchPathDirectory, inDomains domainMask: NSSearchPathDomainMask) -> [AnyObject]

    Objective-C

    - (NSArray *)URLsForDirectory:(NSSearchPathDirectory)directory inDomains:(NSSearchPathDomainMask)domainMask

    Parameters

    directory

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

    domainMask

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

    Return Value

    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.

    Discussion

    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.

    Import Statement

    Swift

    import Foundation

    Availability

    Available in iOS 4.0 and later.

  • Returns the container directory associated with the specified security application group ID.

    Declaration

    Swift

    func containerURLForSecurityApplicationGroupIdentifier(_ groupIdentifier: String) -> NSURL?

    Objective-C

    - (NSURL *)containerURLForSecurityApplicationGroupIdentifier:(NSString *)groupIdentifier

    Discussion

    As explained in App Sandbox Design Guide, groups of sandboxed apps that need to share files and other information can request a container directory as part of their entitlements. These directories are stored in ~/Library/Group Containers/.

    When called with a valid group identifier, this method returns the location of that directory as an NSURL object. This method also creates the directory if it does not yet exist.

    Import Statement

    Swift

    import Foundation

    Availability

    Available in iOS 7.0 and later.

  • Performs a shallow search of the specified directory and returns URLs for the contained items.

    Declaration

    Swift

    func contentsOfDirectoryAtURL(_ url: NSURL, includingPropertiesForKeys keys: [AnyObject]?, options mask: NSDirectoryEnumerationOptions, error error: NSErrorPointer) -> [AnyObject]?

    Objective-C

    - (NSArray *)contentsOfDirectoryAtURL:(NSURL *)url includingPropertiesForKeys:(NSArray *)keys options:(NSDirectoryEnumerationOptions)mask error:(NSError **)error

    Parameters

    url

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

    keys

    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

    Options for the enumeration. Because this method performs only shallow enumerations, options that prevent descending into subdirectories or packages are not allowed; the only supported option is NSDirectoryEnumerationSkipsHiddenFiles.

    error

    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.

    Return Value

    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.

    Discussion

    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.

    Import Statement

    Swift

    import Foundation

    Availability

    Available in iOS 4.0 and later.

  • Performs a shallow search of the specified directory and returns the paths of any contained items.

    Declaration

    Swift

    func contentsOfDirectoryAtPath(_ path: String, error error: NSErrorPointer) -> [AnyObject]?

    Objective-C

    - (NSArray *)contentsOfDirectoryAtPath:(NSString *)path error:(NSError **)error

    Parameters

    path

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

    error

    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.

    Return Value

    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

    Discussion

    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.

    Import Statement

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • Returns a directory enumerator object that can be used to perform a deep enumeration of the directory at the specified URL.

    Declaration

    Swift

    func enumeratorAtURL(_ url: NSURL, includingPropertiesForKeys keys: [AnyObject]?, options mask: NSDirectoryEnumerationOptions, errorHandler handler: ((NSURL!, NSError!) -> Bool)?) -> NSDirectoryEnumerator?

    Objective-C

    - (NSDirectoryEnumerator *)enumeratorAtURL:(NSURL *)url includingPropertiesForKeys:(NSArray *)keys options:(NSDirectoryEnumerationOptions)mask errorHandler:(BOOL (^)(NSURL *url, NSError *error))handler

    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 error handler block for the file manager to call when an error occurs. The handler block should return YEStrue if you want the enumeration to continue or NOfalse if you want the enumeration to stop. The block takes the following parameters:

    url

    An NSURL object that identifies the item for which the error occurred.

    error

    An NSError object that contains information about the error.

    If you specify nil for this parameter, the enumerator object continues to enumerator items as if you had specified a block that returned YEStrue.

    Return Value

    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.

    Discussion

    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 or mount points encountered in the enumeration process, nor does it recurse through them if they point to a directory.

    For example, if you pass a URL that points to /Volumes/MyMountedFileSystem, the returned enumerator will include the entire directory structure for the file system mounted at that location. If, on the other hand, you pass /Volumes, the returned enumerator will include /Volumes/MyMountedFileSystem as one of its results, but will not traverse into the file system mounted there.

    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 its 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”.

    • -(void)scanURLIgnoringExtras:(NSURL *)directoryToScan
    • {
    • // Create a local file manager instance
    • NSFileManager *localFileManager=[[NSFileManager alloc] init];
    • // Enumerate the directory (specified elsewhere in your code)
    • // Request the two properties the method uses, name and isDirectory
    • // Ignore hidden files
    • // The errorHandler: parameter is set to nil. Typically you'd want to present a panel
    • NSDirectoryEnumerator *dirEnumerator = [localFileManager enumeratorAtURL:directoryToScan
    • includingPropertiesForKeys:[NSArray arrayWithObjects:NSURLNameKey,
    • NSURLIsDirectoryKey,nil]
    • options:NSDirectoryEnumerationSkipsHiddenFiles
    • errorHandler:nil];
    • // An array to store the all the enumerated file names in
    • NSMutableArray *theArray=[NSMutableArray array];
    • // Enumerate the dirEnumerator results, each value is stored in allURLs
    • for (NSURL *theURL in dirEnumerator) {
    • // Retrieve the file name. From NSURLNameKey, cached during the enumeration.
    • NSString *fileName;
    • [theURL getResourceValue:&fileName forKey:NSURLNameKey error:NULL];
    • // Retrieve whether a directory. From NSURLIsDirectoryKey, also
    • // cached during the enumeration.
    • NSNumber *isDirectory;
    • [theURL getResourceValue:&isDirectory forKey:NSURLIsDirectoryKey error:NULL];
    • // Ignore files under the _extras directory
    • if (([fileName caseInsensitiveCompare:@"_extras"]==NSOrderedSame) &&
    • ([isDirectory boolValue]==YES))
    • {
    • [dirEnumerator skipDescendants];
    • }
    • else
    • {
    • // Add full path for non directories
    • if ([isDirectory boolValue]==NO)
    • [theArray addObject:theURL];
    • }
    • }
    • // Do something with the path URLs.
    • NSLog(@"theArray - %@",theArray);
    • }

    Import Statement

    Swift

    import Foundation

    Availability

    Available in iOS 4.0 and later.

  • Returns a directory enumerator object that can be used to perform a deep enumeration of the directory at the specified path.

    Declaration

    Swift

    func enumeratorAtPath(_ path: String) -> NSDirectoryEnumerator?

    Objective-C

    - (NSDirectoryEnumerator *)enumeratorAtPath:(NSString *)path

    Parameters

    path

    The path of the directory to enumerate.

    Return Value

    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.

    Discussion

    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:

    • NSString *docsDir = [NSHomeDirectory() stringByAppendingPathComponent: @"Documents"];
    • NSFileManager *localFileManager=[[NSFileManager alloc] init];
    • NSDirectoryEnumerator *dirEnum =
    •     [localFileManager enumeratorAtPath:docsDir];
    • NSString *file;
    • while ((file = [dirEnum nextObject])) {
    •     if ([[file pathExtension] isEqualToString: @"doc"]) {
    • // process the document
    •         [self scanDocument: [docsDir stringByAppendingPathComponent:file]];
    •     }
    • }

    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.

    Import Statement

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • Returns an array of URLs that identify the mounted volumes available on the computer.

    Declaration

    Swift

    func mountedVolumeURLsIncludingResourceValuesForKeys(_ propertyKeys: [AnyObject]?, options options: NSVolumeEnumerationOptions) -> [AnyObject]?

    Objective-C

    - (NSArray *)mountedVolumeURLsIncludingResourceValuesForKeys:(NSArray *)propertyKeys options:(NSVolumeEnumerationOptions)options

    Parameters

    propertyKeys

    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

    Option flags for the enumeration. For a list of possible values, see NSVolumeEnumerationOptions.

    Return Value

    An array of NSURL objects identifying the mounted volumes.

    Discussion

    This call may block if I/O is required to determine values for the requested propertyKeys.

    Import Statement

    Swift

    import Foundation

    Availability

    Available in iOS 4.0 and later.

  • Performs a deep enumeration of the specified directory and returns the paths of all of the contained subdirectories.

    Declaration

    Swift

    func subpathsOfDirectoryAtPath(_ path: String, error error: NSErrorPointer) -> [AnyObject]?

    Objective-C

    - (NSArray *)subpathsOfDirectoryAtPath:(NSString *)path error:(NSError **)error

    Parameters

    path

    The path of the directory to list.

    error

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

    Return Value

    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.

    Discussion

    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.

    Import Statement

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • Returns an array of strings identifying the paths for all items in the specified directory.

    Declaration

    Swift

    func subpathsAtPath(_ path: String) -> [AnyObject]?

    Objective-C

    - (NSArray *)subpathsAtPath:(NSString *)path

    Parameters

    path

    The path of the directory to list.

    Return Value

    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.

    Discussion

    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:

    • BOOL isDir=NO;
    • NSArray *subpaths;
    • NSString *fontPath = @"/System/Library/Fonts";
    • NSFileManager *fileManager = [[NSFileManager alloc] init];
    • if ([fileManager fileExistsAtPath:fontPath isDirectory:&isDir] && isDir)
    • subpaths = [fileManager subpathsAtPath:fontPath];

    Special Considerations

    On OS X v10.5 and later, use subpathsOfDirectoryAtPath:error: instead.

    Import Statement

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later.

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

    Declaration

    Swift

    func createDirectoryAtURL(_ url: NSURL, withIntermediateDirectories createIntermediates: Bool, attributes attributes: [NSObject : AnyObject]?, error error: NSErrorPointer) -> Bool

    Objective-C

    - (BOOL)createDirectoryAtURL:(NSURL *)url withIntermediateDirectories:(BOOL)createIntermediates attributes:(NSDictionary *)attributes error:(NSError **)error

    Parameters

    url

    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

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

    attributes

    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) Mac 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

    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.

    Return Value

    YEStrue if the directory was created, YEStrue if createIntermediates is set and the directory already exists), or NOfalse if an error occurred.

    Discussion

    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.

    Import Statement

    Swift

    import Foundation

    Availability

    Available in iOS 5.0 and later.

  • Creates a directory with given attributes at the specified path.

    Declaration

    Swift

    func createDirectoryAtPath(_ path: String, withIntermediateDirectories createIntermediates: Bool, attributes attributes: [NSObject : AnyObject]?, error error: NSErrorPointer) -> Bool

    Objective-C

    - (BOOL)createDirectoryAtPath:(NSString *)path withIntermediateDirectories:(BOOL)createIntermediates attributes:(NSDictionary *)attributes error:(NSError **)error

    Parameters

    path

    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

    If YEStrue, this method creates any non-existent parent directories as part of creating the directory in path. If NOfalse, 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

    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

    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.

    Return Value

    YEStrue if the directory was created, YEStrue if createIntermediates is set and the directory already exists), or NOfalse if an error occurred.

    Discussion

    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.

    Import Statement

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later.

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

    Declaration

    Swift

    func createFileAtPath(_ path: String, contents contents: NSData?, attributes attributes: [NSObject : AnyObject]?) -> Bool

    Objective-C

    - (BOOL)createFileAtPath:(NSString *)path contents:(NSData *)contents attributes:(NSDictionary *)attributes

    Parameters

    path

    The path for the new file.

    contents

    A data object containing the contents of the new file.

    attributes

    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.

    Return Value

    YEStrue if the operation was successful or if the item already exists, otherwise NOfalse.

    Discussion

    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.

    Import Statement

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • Removes the file or directory at the specified URL.

    Declaration

    Swift

    func removeItemAtURL(_ URL: NSURL, error error: NSErrorPointer) -> Bool

    Objective-C

    - (BOOL)removeItemAtURL:(NSURL *)URL error:(NSError **)error

    Parameters

    URL

    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

    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.

    Return Value

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

    Discussion

    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 YEStrue, 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.

    Removing and item also removes all old versions of that item, invalidating any URLs returned by the URLForPublishingUbiquitousItemAtURL:expirationDate:error: method to old versions.

    Import Statement

    Swift

    import Foundation

    Availability

    Available in iOS 4.0 and later.

  • Removes the file or directory at the specified path.

    Declaration

    Swift

    func removeItemAtPath(_ path: String, error error: NSErrorPointer) -> Bool

    Objective-C

    - (BOOL)removeItemAtPath:(NSString *)path error:(NSError **)error

    Parameters

    path

    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

    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.

    Return Value

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

    Discussion

    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 YEStrue, 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.

    Removing and item also removes all old versions of that item, invalidating any URLs returned by the URLForPublishingUbiquitousItemAtURL:expirationDate:error: method to old versions.

    Import Statement

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • Replaces the contents of the item at the specified URL in a manner that insures no data loss occurs.

    Declaration

    Swift

    func replaceItemAtURL(_ originalItemURL: NSURL, withItemAtURL newItemURL: NSURL, backupItemName backupItemName: String?, options options: NSFileManagerItemReplacementOptions, resultingItemURL resultingURL: AutoreleasingUnsafeMutablePointer<NSURL?>, error error: NSErrorPointer) -> Bool

    Objective-C

    - (BOOL)replaceItemAtURL:(NSURL *)originalItemURL withItemAtURL:(NSURL *)newItemURL backupItemName:(NSString *)backupItemName options:(NSFileManagerItemReplacementOptions)options resultingItemURL:(NSURL **)resultingURL error:(NSError **)error

    Parameters

    originalItemURL

    The item whose contents you want to replace.

    newItemURL

    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

    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

    Specifies the options to use during the replacement. Typically, you pass NSFileManagerItemReplacementUsingNewMetadataOnly 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

    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

    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.

    Return Value

    YEStrue if the replacement was successful or NOfalse if an error occurred.

    Discussion

    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.

    Import Statement

    Swift

    import Foundation

    Availability

    Available in iOS 4.0 and later.

  • Copies the file at the specified URL to a new location synchronously.

    Declaration

    Swift

    func copyItemAtURL(_ srcURL: NSURL, toURL dstURL: NSURL, error error: NSErrorPointer) -> Bool

    Objective-C

    - (BOOL)copyItemAtURL:(NSURL *)srcURL toURL:(NSURL *)dstURL error:(NSError **)error

    Parameters

    srcURL

    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

    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

    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.

    Return Value

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

    Discussion

    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 YEStrue, 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.

    Import Statement

    Swift

    import Foundation

    Availability

    Available in iOS 4.0 and later.

  • Copies the item at the specified path to a new location synchronously.

    Declaration

    Swift

    func copyItemAtPath(_ srcPath: String, toPath dstPath: String, error error: NSErrorPointer) -> Bool

    Objective-C

    - (BOOL)copyItemAtPath:(NSString *)srcPath toPath:(NSString *)dstPath error:(NSError **)error

    Parameters

    srcPath

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

    dstPath

    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

    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.

    Return Value

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

    Discussion

    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 YEStrue, 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.

    Import Statement

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • Moves the file or directory at the specified URL to a new location synchronously.

    Declaration

    Swift

    func moveItemAtURL(_ srcURL: NSURL, toURL dstURL: NSURL, error error: NSErrorPointer) -> Bool

    Objective-C

    - (BOOL)moveItemAtURL:(NSURL *)srcURL toURL:(NSURL *)dstURL error:(NSError **)error

    Parameters

    srcURL

    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

    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

    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.

    Return Value

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

    Discussion

    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 YEStrue, 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.

    Import Statement

    Swift

    import Foundation

    Availability

    Available in iOS 4.0 and later.

  • Moves the file or directory at the specified path to a new location synchronously.

    Declaration

    Swift

    func moveItemAtPath(_ srcPath: String, toPath dstPath: String, error error: NSErrorPointer) -> Bool

    Objective-C

    - (BOOL)moveItemAtPath:(NSString *)srcPath toPath:(NSString *)dstPath error:(NSError **)error

    Parameters

    srcPath

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

    dstPath

    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

    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.

    Return Value

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

    Discussion

    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 YEStrue, 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.

    Import Statement

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • An opaque token that represents the current user’s iCloud identity (read-only)

    Declaration

    Swift

    @NSCopying var ubiquityIdentityToken: protocol<NSCoding, NSCopying, NSObjectProtocol>? { get }

    Objective-C

    @property(readonly, copy) id<NSObject, NSCopying, NSCoding> ubiquityIdentityToken

    Discussion

    When iCloud is currently available, this property contains an opaque object representing the identity of the current user. If iCloud is unavailable for any reason or there is no logged-in user, the value of this property is nil. Accessing the value of this property is relatively fast so you can check the value at launch time from your app’s main thread.

    You can use the token in this property, together with the NSUbiquityIdentityDidChangeNotification notification, to detect when the user logs in or out of iCloud and to detect changes to the active iCloud account. When the user logs in with a different iCloud account, the identity token changes and the system posts the notification. If you stored or archived the previous token, compare that token to the newly obtained one using the isEqual: method to determine if the users are the same or different.

    Accessing the token in this property does not connect your app to its 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.

    Import Statement

    Swift

    import Foundation

    Availability

    Available in iOS 6.0 and later.

  • Returns the URL for the iCloud container associated with the specified identifier and establishes access to that container.

    Declaration

    Swift

    func URLForUbiquityContainerIdentifier(_ containerID: String?) -> NSURL?

    Objective-C

    - (NSURL *)URLForUbiquityContainerIdentifier:(NSString *)containerID

    Parameters

    containerID

    The fully-qualified container identifier for an iCloud container directory. The string you specify must not contain wildcards and must be of the form <TEAMID>.<CONTAINER>, where <TEAMID> is your development team ID and <CONTAINER> is 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 for this parameter, this method returns the first container listed in the com.apple.developer.ubiquity-container-identifiers entitlement array.

    Return Value

    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.

    Discussion

    You use this method to determine the location of your app’s ubiquity container directories and to configure your app’s initial iCloud access. 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. 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.

    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 <TEAM_ID> value, read To view the team ID in Tools Workflow Guide for Mac.

    Import Statement

    Swift

    import Foundation

    Availability

    Available in iOS 5.0 and later.

  • Returns a Boolean indicating whether the item is targeted for storage in iCloud.

    Declaration

    Swift

    func isUbiquitousItemAtURL(_ url: NSURL) -> Bool

    Objective-C

    - (BOOL)isUbiquitousItemAtURL:(NSURL *)url

    Parameters

    url

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

    Return Value

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

    Discussion

    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 YEStrue 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.

    Import Statement

    Swift

    import Foundation

    Availability

    Available in iOS 5.0 and later.

  • Sets whether the item at the specified URL should be stored in the cloud.

    Declaration

    Swift

    func setUbiquitous(_ flag: Bool, itemAtURL url: NSURL, destinationURL destinationURL: NSURL, error errorOut: NSErrorPointer) -> Bool

    Objective-C

    - (BOOL)setUbiquitous:(BOOL)flag itemAtURL:(NSURL *)url destinationURL:(NSURL *)destinationURL error:(NSError **)errorOut

    Parameters

    flag

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

    url

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

    destinationURL

    Moving a file into iCloud 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.

    Moving a file out of iCloud Specify the location on the local device.

    errorOut

    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 to ignore the error information.

    Return Value

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

    Discussion

    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.

    If your app is presenting the file’s contents to the user, it must have an active file presenter object configured to monitor the specified file or directory before calling this method. When you specify YEStrue for the flag parameter, this method attempts to move the file or directory to the cloud and returns YEStrue if it is successful. Calling this method also notifies your file presenter of the new location of the file so that your app can continue to operate on it.

    Import Statement

    Swift

    import Foundation

    Availability

    Available in iOS 5.0 and later.

  • Starts downloading (if necessary) the specified item to the local system.

    Declaration

    Swift

    func startDownloadingUbiquitousItemAtURL(_ url: NSURL, error errorOut: NSErrorPointer) -> Bool

    Objective-C

    - (BOOL)startDownloadingUbiquitousItemAtURL:(NSURL *)url error:(NSError **)errorOut

    Parameters

    url

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

    errorOut

    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 to ignore the error information.

    Return Value

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

    Discussion

    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.

    Import Statement

    Swift

    import Foundation

    Availability

    Available in iOS 5.0 and later.

  • Removes the local copy of the specified cloud-based item.

    Declaration

    Swift

    func evictUbiquitousItemAtURL(_ url: NSURL, error errorOut: NSErrorPointer) -> Bool

    Objective-C

    - (BOOL)evictUbiquitousItemAtURL:(NSURL *)url error:(NSError **)errorOut

    Parameters

    url

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

    errorOut

    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 to ignore the error information.

    Return Value

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

    Discussion

    Do not use a coordinated write to perform this operation. On OS X v10.7 or earlier, the framework takes a coordinated write in its implementation of this method, so taking one in your app causes a deadlock. On OS X v10.8 and later, the framework detects coordination done by your app on the same thread as the call to this method, to avoid deadlocking.

    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.

    Import Statement

    Swift

    import Foundation

    Availability

    Available in iOS 5.0 and later.

  • Returns a URL that can be emailed to users to allow them to download a copy of a cloud-based item.

    Declaration

    Swift

    func URLForPublishingUbiquitousItemAtURL(_ url: NSURL, expirationDate outDate: AutoreleasingUnsafeMutablePointer<NSDate?>, error error: NSErrorPointer) -> NSURL?

    Objective-C

    - (NSURL *)URLForPublishingUbiquitousItemAtURL:(NSURL *)url expirationDate:(NSDate **)outDate error:(NSError **)error

    Parameters

    url

    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. The file at the specified URL must already be uploaded to iCloud when you call this method.

    outDate

    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

    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.

    Return Value

    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.

    Discussion

    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. Explicitly deleting the item by calling the removeItemAtURL:error: or removeItemAtPath:error: method also deletes all old versions of the item, invalidating URLs to those versions returned by this method.

    Your app must have access to the network for this call to succeed. If the specified file is in the process of being uploaded to iCloud, you must not call this method until the upload has finished.

    Import Statement

    Swift

    import Foundation

    Availability

    Available in iOS 5.0 and later.

  • Creates a symbolic link at the specified URL that points to an item at the given URL.

    Declaration

    Swift

    func createSymbolicLinkAtURL(_ url: NSURL, withDestinationURL destURL: NSURL, error error: NSErrorPointer) -> Bool

    Objective-C

    - (BOOL)createSymbolicLinkAtURL:(NSURL *)url withDestinationURL:(NSURL *)destURL error:(NSError **)error

    Parameters

    url

    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

    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

    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.

    Return Value

    YEStrue if the symbolic link was created or NOfalse if an error occurred. This method also returns NOfalse if a file, directory, or link already exists at url.

    Discussion

    This method does not traverse symbolic links contained in destURL, making it possible to create symbolic links to locations that do not yet exist. Also, if the final path component in url is a symbolic link, that link is not followed.

    Import Statement

    Swift

    import Foundation

    Availability

    Available in iOS 5.0 and later.

  • Creates a symbolic link that points to the specified destination.

    Declaration

    Swift

    func createSymbolicLinkAtPath(_ path: String, withDestinationPath destPath: String, error error: NSErrorPointer) -> Bool

    Objective-C

    - (BOOL)createSymbolicLinkAtPath:(NSString *)path withDestinationPath:(NSString *)destPath error:(NSError **)error

    Parameters

    path

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

    destPath

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

    error

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

    Return Value

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

    Discussion

    This method does not traverse symbolic links contained in destPath, making it possible to create symbolic links to locations that do not yet exist. Also, if the final path component in path is a symbolic link, that link is not followed.

    Import Statement

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • Creates a hard link between the items at the specified URLs.

    Declaration

    Swift

    func linkItemAtURL(_ srcURL: NSURL, toURL dstURL: NSURL, error error: NSErrorPointer) -> Bool

    Objective-C

    - (BOOL)linkItemAtURL:(NSURL *)srcURL toURL:(NSURL *)dstURL error:(NSError **)error

    Parameters

    srcURL

    The file URL that identifies the source 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

    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

    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.

    Return Value

    YEStrue if the hard link was created or NOfalse if an error occurred. This method also returns NOfalse if a file, directory, or link already exists at dstURL.

    Discussion

    Use this method to create hard links between files in the current file system. If srcURL is a directory, this method creates a new directory at dstURL and then creates hard links for the items in that directory. If srcURL is (or contains) a symbolic link, the symbolic link is copied and not converted to a hard link at dstURL.

    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 YEStrue, 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.

    Import Statement

    Swift

    import Foundation

    Availability

    Available in iOS 4.0 and later.

  • Creates a hard link between the items at the specified paths.

    Declaration

    Swift

    func linkItemAtPath(_ srcPath: String, toPath dstPath: String, error error: NSErrorPointer) -> Bool

    Objective-C

    - (BOOL)linkItemAtPath:(NSString *)srcPath toPath:(NSString *)dstPath error:(NSError **)error

    Parameters

    srcPath

    The path that specifies the item you wish to link to. The value in this parameter must not be nil.

    dstPath

    The path that identifies the location where the link will be created. The value in this parameter must not be nil.

    error

    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.

    Return Value

    YEStrue if the hard link was created or NOfalse if an error occurred. This method also returns NOfalse if a file, directory, or link already exists at dstPath.

    Discussion

    Use this method to create hard links between files in the current file system. If srcPath is a directory, this method creates a new directory at dstPath and then creates hard links for the items in that directory. If srcPath 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 YEStrue, 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.

    Import Statement

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later.

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

    Declaration

    Swift

    func destinationOfSymbolicLinkAtPath(_ path: String, error error: NSErrorPointer) -> String?

    Objective-C

    - (NSString *)destinationOfSymbolicLinkAtPath:(NSString *)path error:(NSError **)error

    Parameters

    path

    The path of a file or directory.

    error

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

    Return Value

    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.

    Import Statement

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • Returns a Boolean value that indicates whether a file or directory exists at a specified path.

    Declaration

    Swift

    func fileExistsAtPath(_ path: String) -> Bool

    Objective-C

    - (BOOL)fileExistsAtPath:(NSString *)path

    Parameters

    path

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

    Return Value

    YEStrue if a file at the specified path exists, or NOfalse if the file does not exist or its existence could not be determined.

    Discussion

    If the file at path is inaccessible to your app, perhaps because one or more parent directories are inaccessible, this method returns NOfalse. If the final element in path specifies a symbolic link, this method traverses the link and returns YEStrue or NOfalse based on the existence of the file at the link destination.

    Import Statement

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • Returns a Boolean value that indicates whether a file or directory exists at a specified path. The isDirectory out parameter indicates whether the path points to a directory or a regular file.

    Declaration

    Swift

    func fileExistsAtPath(_ path: String, isDirectory isDirectory: UnsafeMutablePointer<ObjCBool>) -> Bool

    Objective-C

    - (BOOL)fileExistsAtPath:(NSString *)path isDirectory:(BOOL *)isDirectory

    Parameters

    path

    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 NOfalse.

    isDirectory

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

    Return Value

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

    Discussion

    If the file at path is inaccessible to your app, perhaps because one or more parent directories are inaccessible, this method returns NOfalse. If the final element in path specifies a symbolic link, this method traverses the link and returns YEStrue or NOfalse based on the existence of the file at the link destination.

    If you need to further determine whether 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:

    • NSArray *subpaths;
    • BOOL isDir;
    • NSArray *paths = NSSearchPathForDirectoriesInDomains
    • (NSLibraryDirectory, NSUserDomainMask, YES);
    • if ([paths count] == 1) {
    • NSFileManager *fileManager = [[NSFileManager alloc] init];
    • NSString *fontPath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"Fonts"];
    • if ([fileManager fileExistsAtPath:fontPath isDirectory:&isDir] && isDir) {
    • subpaths = [fileManager subpathsAtPath:fontPath];
    • // ...

    Import Statement

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • Returns a Boolean value that indicates whether the invoking object appears able to read a specified file.

    Declaration

    Swift

    func isReadableFileAtPath(_ path: String) -> Bool

    Objective-C

    - (BOOL)isReadableFileAtPath:(NSString *)path

    Parameters

    path

    A file path.

    Return Value

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

    Discussion

    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 NOfalse. 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.

    Import Statement

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • Returns a Boolean value that indicates whether the invoking object appears able to write to a specified file.

    Declaration

    Swift

    func isWritableFileAtPath(_ path: String) -> Bool

    Objective-C

    - (BOOL)isWritableFileAtPath:(NSString *)path

    Parameters

    path

    A file path.

    Return Value

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

    Discussion

    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 NOfalse. 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.

    Import Statement

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • Returns a Boolean value that indicates whether the operating system appears able to execute a specified file.

    Declaration

    Swift

    func isExecutableFileAtPath(_ path: String) -> Bool

    Objective-C

    - (BOOL)isExecutableFileAtPath:(NSString *)path

    Parameters

    path

    A file path.

    Return Value

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

    Discussion

    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 NOfalse. 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.

    Import Statement

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • Returns a Boolean value that indicates whether the invoking object appears able to delete a specified file.

    Declaration

    Swift

    func isDeletableFileAtPath(_ path: String) -> Bool

    Objective-C

    - (BOOL)isDeletableFileAtPath:(NSString *)path

    Parameters

    path

    A file path.

    Return Value

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

    Discussion

    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 NOfalse. If the item at path is a symbolic link, it is not traversed.

    Import Statement

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • Returns an array of strings representing the user-visible components of a given path.

    Declaration

    Swift

    func componentsToDisplayForPath(_ path: String) -> [AnyObject]?

    Objective-C

    - (NSArray *)componentsToDisplayForPath:(NSString *)path

    Parameters

    path

    A pathname.

    Return Value

    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.

    Discussion

    These components cannot be used for path operations and are only suitable for display to the user.

    Import Statement

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • Returns the display name of the file or directory at a specified path.

    Declaration

    Swift

    func displayNameAtPath(_ path: String) -> String

    Objective-C

    - (NSString *)displayNameAtPath:(NSString *)path

    Parameters

    path

    The path of a file or directory.

    Return Value

    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.

    Discussion

    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.

    • NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
    • if ([paths count] > 0)
    • {
    • NSString *documentsDirectory = [paths objectAtIndex:0];
    • NSFileManager *fileManager = [[NSFileManager alloc] init];
    • NSString *displayNameAtPath = [fileManager displayNameAtPath:documentsDirectory];
    • NSLog(@"%@", displayNameAtPath);
    • }

    Import Statement

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • Returns the attributes of the item at a given path.

    Declaration

    Swift

    func attributesOfItemAtPath(_ path: String, error error: NSErrorPointer) -> [NSObject : AnyObject]?

    Objective-C

    - (NSDictionary *)attributesOfItemAtPath:(NSString *)path error:(NSError **)error

    Parameters

    path

    The path of a file or directory.

    error

    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.

    Return Value

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

    Special Considerations

    If the item at the path is a symbolic link—that is, the value of the NSFileType key in the attributes dictionary is NSFileTypeSymbolicLink—you can use the destinationOfSymbolicLinkAtPath:error: method to retrieve the path of the item pointed to by the link. You can also use the stringByResolvingSymlinksInPath method of NSString to resolve links in the path before retrieving the item’s attributes.

    As a convenience, NSDictionary provides a set of methods (declared as a category on NSDictionary) for quickly and efficiently obtaining attribute information from the returned dictionary: fileGroupOwnerAccountName, fileModificationDate, fileOwnerAccountName, filePosixPermissions, fileSize, fileSystemFileNumber, fileSystemNumber, and fileType.

    Import Statement

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • Returns a dictionary that describes the attributes of the mounted file system on which a given path resides.

    Declaration

    Swift

    func attributesOfFileSystemForPath(_ path: String, error error: NSErrorPointer) -> [NSObject : AnyObject]?

    Objective-C

    - (NSDictionary *)attributesOfFileSystemForPath:(NSString *)path error:(NSError **)error

    Parameters

    path

    Any pathname within the mounted file system.

    error

    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.

    Return Value

    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.

    Discussion

    This method does not traverse a terminal symbolic link.

    Import Statement

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • Sets the attributes of the specified file or directory.

    Declaration

    Swift

    func setAttributes(_ attributes: [NSObject : AnyObject], ofItemAtPath path: String, error error: NSErrorPointer) -> Bool

    Objective-C

    - (BOOL)setAttributes:(NSDictionary *)attributes ofItemAtPath:(NSString *)path error:(NSError **)error

    Parameters

    attributes

    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

    The path of a file or directory.

    error

    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.

    Return Value

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

    Discussion

    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.

    Import Statement

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • Returns the contents of the file at the specified path.

    Declaration

    Swift

    func contentsAtPath(_ path: String) -> NSData?

    Objective-C

    - (NSData *)contentsAtPath:(NSString *)path

    Parameters

    path

    The path of the file whose contents you want.

    Return Value

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

    Import Statement

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • Returns a Boolean value that indicates whether the files or directories in specified paths have the same contents.

    Declaration

    Swift

    func contentsEqualAtPath(_ path1: String, andPath path2: String) -> Bool

    Objective-C

    - (BOOL)contentsEqualAtPath:(NSString *)path1 andPath:(NSString *)path2

    Parameters

    path1

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

    path2

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

    Return Value

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

    Discussion

    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.

    Import Statement

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • Determines the type of relationship that exists between a directory and item.

    Declaration

    Swift

    func getRelationship(_ outRelationship: UnsafeMutablePointer<NSURLRelationship>, ofDirectoryAtURL directoryURL: NSURL, toItemAtURL otherURL: NSURL, error error: NSErrorPointer) -> Bool

    Objective-C

    - (BOOL)getRelationship:(NSURLRelationship *)outRelationship ofDirectoryAtURL:(NSURL *)directoryURL toItemAtURL:(NSURL *)otherURL error:(NSError **)error

    Parameters

    outRelationship

    A pointer to a variable in which to put the relationship between directoryURL and otherURL. For a list of possible values, see NSURLRelationship.

    directoryURL

    The URL of the directory that potentially contains the item in otherURL. The URL in this parameter must specify a directory. This parameter must not be nil.

    otherURL

    The URL of the file or directory whose relationship to directoryURL is being tested. This parameter must not be nil.

    error

    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.

    Return Value

    YEStrue if the relationship between the items was successfully determined, or NOfalse if an error occurred.

    Discussion

    Use this method to determine the relationship between an item and a directory whose location you already know. If the relationship between the items is determined successfully, this method sets the value of the outRelationship parameter to an appropriate value and returns YEStrue. The directory may contain the item, it may be the same as the item, or it may not have a direct relationship to the item.

    Import Statement

    Swift

    import Foundation

    Availability

    Available in iOS 8.0 and later.

  • Determines the type of relationship that exists between a system directory and the specified item.

    Declaration

    Swift

    func getRelationship(_ outRelationship: UnsafeMutablePointer<NSURLRelationship>, ofDirectory directory: NSSearchPathDirectory, inDomain domainMask: NSSearchPathDomainMask, toItemAtURL url: NSURL, error error: NSErrorPointer) -> Bool

    Objective-C

    - (BOOL)getRelationship:(NSURLRelationship *)outRelationship ofDirectory:(NSSearchPathDirectory)directory inDomain:(NSSearchPathDomainMask)domainMask toItemAtURL:(NSURL *)url error:(NSError **)error

    Parameters

    outRelationship

    A pointer to a variable in which to put the relationship between directoryURL and otherURL. For a list of possible values, see NSURLRelationship.

    directory

    The search path directory. For a list of possible values, see NSSearchPathDirectory.

    domainMask

    The file system domain to search. Specify 0 for this parameter if you want the file manager to choose the domain that is most appropriate for the specified url.

    url

    The URL of the file or directory whose relationship to directoryURL is being tested. This parameter must not be nil.

    error

    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.

    Return Value

    YEStrue if the relationship between the items was successfully determined, or NOfalse if an error occurred.

    Discussion

    Use this method to determine the relationship between an item and one of the system-specific directories. For example, you might use this method to determine if the specified item is in the user’s Documents directory or is in the trash. If the relationship between the items is determined successfully, this method sets the value of the outRelationship parameter to an appropriate value and returns YEStrue. The directory may contain the item, it may be the same as the item, or it may not have a direct relationship to the item.

    Import Statement

    Swift

    import Foundation

    Availability

    Available in iOS 8.0 and later.

  • Returns a C-string representation of a given path that properly encodes Unicode strings for use by the file system.

    Declaration

    Swift

    func fileSystemRepresentationWithPath(_ path: String) -> UnsafePointer<Int8>

    Objective-C

    - (const char *)fileSystemRepresentationWithPath:(NSString *)path

    Parameters

    path

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

    Return Value

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

    Discussion

    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.

    Import Statement

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • Returns an NSString object whose contents are derived from the specified C-string path.

    Declaration

    Swift

    func stringWithFileSystemRepresentation(_ string: UnsafePointer<Int8>, length len: Int) -> String

    Objective-C

    - (NSString *)stringWithFileSystemRepresentation:(const char *)string length:(NSUInteger)len

    Parameters

    string

    A C string representation of a pathname.

    len

    The number of characters in string.

    Return Value

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

    Discussion

    Use this method if your code receives paths as C strings from system routines.

    Import Statement

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • delegate delegate Property

    The delegate of the file manager object.

    Declaration

    Swift

    unowned(unsafe) var delegate: NSFileManagerDelegate?

    Objective-C

    @property(assign) id< NSFileManagerDelegate > delegate

    Discussion

    It is recommended that you assign a delegate to the file manager object only if you allocated and initialized the object yourself. Avoid assigning a delegate to the shared file manager obtained from the defaultManager method.

    The default value of this property is nil. When assigning a delegate to this property, your object must conform to the NSFileManagerDelegate protocol.

    Import Statement

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • Changes the attributes of a given file or directory.

    Deprecation Statement

    Use setAttributes:ofItemAtPath:error: instead.

    Declaration

    Objective-C

    - (BOOL)changeFileAttributes:(NSDictionary *)attributes atPath:(NSString *)path

    Parameters

    attributes

    A dictionary containing as keys the attributes to set for path and as values the corresponding value for the attribute. You can set following: 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.

    For the NSFilePosixPermissions value, specify a file mode from the OR’d permission bit masks defined in sys/stat.h. See the man page for the chmod function (man 2 chmod) for an explanation.

    path

    A path to a file or directory.

    Return Value

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

    Discussion

    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.

    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.

    Special Considerations

    Because this method does not return error information, it has been deprecated as of OS X v10.5. Use setAttributes:ofItemAtPath:error: instead.

    Availability

    Available in iOS 2.0 and later.

    Deprecated in iOS 2.0.

  • Returns a dictionary that describes the POSIX attributes of the file specified at a given.

    Deprecation Statement

    Use attributesOfItemAtPath:error: instead.

    Declaration

    Objective-C

    - (NSDictionary *)fileAttributesAtPath:(NSString *)path traverseLink:(BOOL)flag

    Parameters

    path

    A file path.

    flag

    If path is not a symbolic link, this parameter has no effect. If path is a symbolic link, then:

    • If YEStrue the attributes of the linked-to file are returned, or if the link points to a nonexistent file the method returns nil.

    • If NOfalse, the attributes of the symbolic link are returned.

    Return Value

    An NSDictionary object that describes the POSIX attributes of the file specified at path. The keys in the dictionary are described in “File Attribute Keys”. If there is no item at path, returns nil.

    Discussion

    This code example gets several attributes of a file and logs them.

    • NSFileManager *fileManager = [[NSFileManager alloc] init];
    • NSString *path = @"/tmp/List";
    • NSDictionary *fileAttributes = [fileManager fileAttributesAtPath:path traverseLink:YES];
    • if (fileAttributes != nil) {
    • NSNumber *fileSize;
    • NSString *fileOwner;
    • NSDate *fileModDate;
    • if (fileSize = [fileAttributes objectForKey:NSFileSize]) {
    • NSLog(@"File size: %qi\n", [fileSize unsignedLongLongValue]);
    • }
    • if (fileOwner = [fileAttributes objectForKey:NSFileOwnerAccountName]) {
    • NSLog(@"Owner: %@\n", fileOwner);
    • }
    • if (fileModDate = [fileAttributes objectForKey:NSFileModificationDate]) {
    • NSLog(@"Modification date: %@\n", fileModDate);
    • }
    • }
    • else {
    • NSLog(@"Path (%@) is invalid.", path);
    • }

    As a convenience, NSDictionary provides a set of methods (declared as a category in NSFileManager.h) for quickly and efficiently obtaining attribute information from the returned dictionary: fileGroupOwnerAccountName, fileModificationDate, fileOwnerAccountName, filePosixPermissions, fileSize, fileSystemFileNumber, fileSystemNumber, and fileType. For example, you could rewrite the file modification statement in the code example above as:

    • if (fileModDate = [fileAttributes fileModificationDate])
    • NSLog(@"Modification date: %@\n", fileModDate);

    Special Considerations

    Because this method does not return error information, it has been deprecated as of OS X v10.5. Use attributesOfItemAtPath:error: instead.

    Availability

    Available in iOS 2.0 and later.

    Deprecated in iOS 2.0.

  • Returns a dictionary that describes the attributes of the mounted file system on which a given path resides.

    Deprecation Statement

    Use attributesOfFileSystemForPath:error: instead.

    Declaration

    Objective-C

    - (NSDictionary *)fileSystemAttributesAtPath:(NSString *)path

    Parameters

    path

    Any pathname within the mounted file system.

    Return Value

    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.

    Special Considerations

    Because this method does not return error information, it has been deprecated as of OS X v10.5. Use attributesOfFileSystemForPath:error: instead.

    Availability

    Available in iOS 2.0 and later.

    Deprecated in iOS 2.0.

  • Returns the directories and files (including symbolic links) contained in a given directory.

    Deprecation Statement

    Use contentsOfDirectoryAtPath:error: instead.

    Declaration

    Objective-C

    - (NSArray *)directoryContentsAtPath:(NSString *)path

    Parameters

    path

    A path to a directory.

    Return Value

    An array of NSString objects identifying the directories and files (including symbolic links) contained in path. Returns an empty array if the directory exists but has no contents. Returns nil if the directory specified at path does not exist or there is some other error accessing it.

    Discussion

    The search is shallow, and therefore does not return the contents of any subdirectories and does not traverse symbolic links in the specified directory. This returned array does not contain strings for the current directory (“.”), parent directory (“..”), or resource forks (begin with “._”).

    Special Considerations

    Because this method does not return error information, it has been deprecated as of OS X v10.5. Use contentsOfDirectoryAtPath:error: instead.

    Availability

    Available in iOS 2.0 and later.

    Deprecated in iOS 2.0.

  • Creates a directory (without contents) at a given path with given attributes.

    Declaration

    Objective-C

    - (BOOL)createDirectoryAtPath:(NSString *)path attributes:(NSDictionary *)attributes

    Parameters

    path

    The path at which to create the new directory. The directory to be created must not yet exist, but its parent directory must exist.

    attributes

    The file attributes for the new directory. The attributes you can set are owner and group numbers, file permissions, and modification date. If you specify nil for attributes, default values for these attributes are set (particularly write access for the creator and read access for others). 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.

    Return Value

    YEStrue if the operation was successful, otherwise NOfalse.

    Special Considerations

    Because this method does not return error information, it has been deprecated as of OS X v10.5. Use createDirectoryAtPath:withIntermediateDirectories:attributes:error: instead.

    Availability

    Available in iOS 2.0 and later.

    Deprecated in iOS 2.0.

  • Creates a symbolic link identified by a given path that refers to a given location.

    Deprecation Statement

    Use createSymbolicLinkAtURL:withDestinationURL:error: instead.

    Declaration

    Objective-C

    - (BOOL)createSymbolicLinkAtPath:(NSString *)path pathContent:(NSString *)otherPath

    Parameters

    path

    The path for a symbolic link.

    otherPath

    The path to which path should refer.

    Return Value

    YEStrue if the operation is successful, otherwise NOfalse. Returns NOfalse if a file, directory, or symbolic link identical to path already exists.

    Discussion

    Creates a symbolic link identified by path that refers to the location otherPath in the file system.

    Special Considerations

    Because this method does not return error information, it has been deprecated as of OS X v10.5. Use createSymbolicLinkAtPath:withDestinationPath:error: instead.

    Availability

    Available in iOS 2.0 and later.

    Deprecated in iOS 2.0.

  • Returns the path of the directory or file that a symbolic link at a given path refers to.

    Deprecation Statement

    Use destinationOfSymbolicLinkAtPath:error: instead.

    Declaration

    Objective-C

    - (NSString *)pathContentOfSymbolicLinkAtPath:(NSString *)path

    Parameters

    path

    The path of a symbolic link.

    Return Value

    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.

    Special Considerations

    Because this method does not return error information, it has been deprecated as of OS X v10.5. Use destinationOfSymbolicLinkAtPath:error: instead.

    Availability

    Available in iOS 2.0 and later.

    Deprecated in iOS 2.0.

  • An NSFileManager object sends this message to its handler for each error it encounters when copying, moving, removing, or linking files or directories.

    Deprecation Statement

    See delegate methods for copy, move, remove, and link methods.

    Declaration

    Objective-C

    - (BOOL)fileManager:(NSFileManager *)manager shouldProceedAfterError:(NSDictionary *)errorInfo

    Discussion

    An NSFileManager object, manager, sends this message for each error it encounters when copying, moving, removing, or linking files or directories. The return value is passed back to the invoker of copyPath:toPath:handler:, movePath:toPath:handler:, removeFileAtPath:handler:, or linkPath:toPath:handler:. If an error occurs and your handler has not implemented this method, the invoking method automatically returns NOfalse.

    Availability

    Available in iOS 2.0 and later.

    Deprecated in iOS 2.0.

  • An NSFileManager object sends this message to a handler immediately before attempting to move, copy, rename, or delete, or before attempting to link to a given path.

    Deprecation Statement

    See delegate methods for copy, move, link, and remove methods.

    Declaration

    Objective-C

    - (void)fileManager:(NSFileManager *)manager willProcessPath:(NSString *)path

    Discussion

    You can implement this method in your handler to monitor file operations.

    Availability

    Available in iOS 2.0 and later.

    Deprecated in iOS 2.0.

  • Options for enumerating mounted volumes with the mountedVolumeURLsIncludingResourceValuesForKeys:options: method.

    Declaration

    Swift

    struct NSVolumeEnumerationOptions : RawOptionSetType { init(_ rawValue: UInt) init(rawValue rawValue: UInt) static var SkipHiddenVolumes: NSVolumeEnumerationOptions { get } static var ProduceFileReferenceURLs: NSVolumeEnumerationOptions { get } }

    Objective-C

    typedef enum : NSUInteger { NSVolumeEnumerationSkipHiddenVolumes = 1L << 1, NSVolumeEnumerationProduceFileReferenceURLs = 1L << 2 } NSVolumeEnumerationOptions;

    Constants

    • SkipHiddenVolumes

      NSVolumeEnumerationSkipHiddenVolumes

      The enumeration skips hidden volumes.

      Available in iOS 4.0 and later.

    • ProduceFileReferenceURLs

      NSVolumeEnumerationProduceFileReferenceURLs

      The enumeration produces file reference URLs rather than path-based URLs.

      Available in iOS 4.0 and later.

    Import Statement

    Swift

    import Foundation

    Availability

    Available in iOS 4.0 and later.

  • Options for enumerating the contents of directories with the contentsOfDirectoryAtURL:includingPropertiesForKeys:options:error: method.

    Declaration

    Swift

    struct NSDirectoryEnumerationOptions : RawOptionSetType { init(_ rawValue: UInt) init(rawValue rawValue: UInt) static var SkipsSubdirectoryDescendants: NSDirectoryEnumerationOptions { get } static var SkipsPackageDescendants: NSDirectoryEnumerationOptions { get } static var SkipsHiddenFiles: NSDirectoryEnumerationOptions { get } }

    Objective-C

    typedef enum : NSUInteger { NSDirectoryEnumerationSkipsSubdirectoryDescendants = 1L << 0, NSDirectoryEnumerationSkipsPackageDescendants = 1L << 1, NSDirectoryEnumerationSkipsHiddenFiles = 1L << 2 } NSDirectoryEnumerationOptions;

    Constants

    • SkipsSubdirectoryDescendants

      NSDirectoryEnumerationSkipsSubdirectoryDescendants

      Perform a shallow enumeration; do not descend into directories.

      Available in iOS 4.0 and later.

    • SkipsPackageDescendants

      NSDirectoryEnumerationSkipsPackageDescendants

      Do not descend into packages.

      Available in iOS 4.0 and later.

    • SkipsHiddenFiles

      NSDirectoryEnumerationSkipsHiddenFiles

      Do not enumerate hidden files.

      Available in iOS 4.0 and later.

    Import Statement

    Swift

    import Foundation

    Availability

    Available in iOS 4.0 and later.

  • The constants specify the replacement behavior in replaceItemAtURL:withItemAtURL:backupItemName:options:resultingItemURL:error:.

    Declaration

    Swift

    struct NSFileManagerItemReplacementOptions : RawOptionSetType { init(_ rawValue: UInt) init(rawValue rawValue: UInt) static var UsingNewMetadataOnly: NSFileManagerItemReplacementOptions { get } static var WithoutDeletingBackupItem: NSFileManagerItemReplacementOptions { get } }

    Objective-C

    typedef enum : NSUInteger { NSFileManagerItemReplacementUsingNewMetadataOnly = 1UL << 0, NSFileManagerItemReplacementWithoutDeletingBackupItem = 1UL << 1 } NSFileManagerItemReplacementOptions;

    Constants

    Import Statement

    Swift

    import Foundation

    Availability

    Available in iOS 4.0 and later.

  • Declaration

    Swift

    let NSFileAppendOnly: String let NSFileBusy: String let NSFileCreationDate: String let NSFileOwnerAccountName: String let NSFileGroupOwnerAccountName: String let NSFileDeviceIdentifier: String let NSFileExtensionHidden: String let NSFileGroupOwnerAccountID: String let NSFileHFSCreatorCode: String let NSFileHFSTypeCode: String let NSFileImmutable: String let NSFileModificationDate: String let NSFileOwnerAccountID: String let NSFilePosixPermissions: String let NSFileReferenceCount: String let NSFileSize: String let NSFileSystemFileNumber: String let NSFileType: String let NSFileProtectionKey: String

    Objective-C

    NSString * const NSFileType; NSString * const NSFileSize; NSString * const NSFileModificationDate; NSString * const NSFileReferenceCount; NSString * const NSFileDeviceIdentifier; NSString * const NSFileOwnerAccountName; NSString * const NSFileGroupOwnerAccountName; NSString * const NSFilePosixPermissions; NSString * const NSFileSystemNumber; NSString * const NSFileSystemFileNumber; NSString * const NSFileExtensionHidden; NSString * const NSFileHFSCreatorCode; NSString * const NSFileHFSTypeCode; NSString * const NSFileImmutable; NSString * const NSFileAppendOnly; NSString * const NSFileCreationDate; NSString * const NSFileOwnerAccountID; NSString * const NSFileGroupOwnerAccountID; NSString * const NSFileBusy; NSString* const NSFileProtectionKey;

    Constants

    • NSFileAppendOnly

      NSFileAppendOnly

      The key in a file attribute dictionary whose value indicates whether the file is read-only.

      The corresponding value is an NSNumber object containing a Boolean value.

      Available in iOS 2.0 and later.

    • NSFileBusy

      NSFileBusy

      The key in a file attribute dictionary whose value indicates whether the file is busy.

      The corresponding value is an NSNumber object containing a Boolean value.

      Available in iOS 2.0 and later.

    • NSFileCreationDate

      NSFileCreationDate

      The key in a file attribute dictionary whose value indicates the file's creation date.

      The corresponding value is an NSDate object.

      Available in iOS 2.0 and later.

    • NSFileOwnerAccountName

      NSFileOwnerAccountName

      The key in a file attribute dictionary whose value indicates the name of the file's owner.

      The corresponding value is an NSString object.

      Available in iOS 2.0 and later.

    • NSFileGroupOwnerAccountName

      NSFileGroupOwnerAccountName

      The key in a file attribute dictionary whose value indicates the group name of the file's owner.

      The corresponding value is an NSString object.

      Available in iOS 2.0 and later.

    • NSFileDeviceIdentifier

      NSFileDeviceIdentifier

      The key in a file attribute dictionary whose value indicates the identifier for the device on which the file resides.

      The corresponding value is an NSNumber object containing an unsigned long.

      Available in iOS 2.0 and later.

    • NSFileExtensionHidden

      NSFileExtensionHidden

      The key in a file attribute dictionary whose value indicates whether the file's extension is hidden.

      The corresponding value is an NSNumber object containing a Boolean value.

      Available in iOS 2.0 and later.

    • NSFileGroupOwnerAccountID

      NSFileGroupOwnerAccountID

      The key in a file attribute dictionary whose value indicates the file's group ID.

      The corresponding value is an NSNumber object containing an unsigned long.

      Available in iOS 2.0 and later.

    • NSFileHFSCreatorCode

      NSFileHFSCreatorCode

      The key in a file attribute dictionary whose value indicates the file's HFS creator code.

      The corresponding value is an NSNumber object containing an unsigned long. See HFS File Types for possible values.

      Available in iOS 2.0 and later.

    • NSFileHFSTypeCode

      NSFileHFSTypeCode

      The key in a file attribute dictionary whose value indicates the file's HFS type code.

      The corresponding value is an NSNumber object containing an unsigned long. See HFS File Types for possible values.

      Available in iOS 2.0 and later.

    • NSFileImmutable

      NSFileImmutable

      The key in a file attribute dictionary whose value indicates whether the file is mutable.

      The corresponding value is an NSNumber object containing a Boolean value.

      Available in iOS 2.0 and later.

    • NSFileModificationDate

      NSFileModificationDate

      The key in a file attribute dictionary whose value indicates the file's last modified date.

      The corresponding value is an NSDate object.

      Available in iOS 2.0 and later.

    • NSFileOwnerAccountID

      NSFileOwnerAccountID

      The key in a file attribute dictionary whose value indicates the file's owner's account ID.

      The corresponding value is an NSNumber object containing an unsigned long.

      Available in iOS 2.0 and later.

    • NSFilePosixPermissions

      NSFilePosixPermissions

      The key in a file attribute dictionary whose value indicates the file's Posix permissions.

      The corresponding value is an NSNumber object. Use the shortValue method to retrieve the integer value for the permissions.

      Available in iOS 2.0 and later.

    • NSFileReferenceCount

      NSFileReferenceCount

      The key in a file attribute dictionary whose value indicates the file's reference count.

      The corresponding value is an NSNumber object containing an unsigned long.

      The number specifies the number of hard links to a file.

      Available in iOS 2.0 and later.

    • NSFileSize

      NSFileSize

      The key in a file attribute dictionary whose value indicates the file's size in bytes.

      The corresponding value is an NSNumber object containing an unsigned long long.

      Available in iOS 2.0 and later.

    • NSFileSystemFileNumber

      NSFileSystemFileNumber

      The key in a file attribute dictionary whose value indicates the file's filesystem file number.

      The corresponding value is an NSNumber object containing an unsigned long. The value corresponds to the value of st_ino, as returned by stat(2).

      Available in iOS 2.0 and later.

    • NSFileType

      NSFileType

      The key in a file attribute dictionary whose value indicates the file's type.

      The corresponding value is an NSString object (see NSFileType Attribute Values for possible values).

      Available in iOS 2.0 and later.

    • NSFileProtectionKey

      NSFileProtectionKey

      The extended attribute key that identifies the protection level for this file. The corresponding value is an NSString value. For a list of possible values, see File Protection Values.

      Available in iOS 4.0 and later.

    Discussion

    NSFileDeviceIdentifier is used to access the identifier of a remote device.

  • These strings are the possible values for the NSFileType attribute key contained in the dictionary object returned by attributesOfItemAtPath:error:.

    Declaration

    Swift

    let NSFileTypeDirectory: String let NSFileTypeRegular: String let NSFileTypeSymbolicLink: String let NSFileTypeSocket: String let NSFileTypeCharacterSpecial: String let NSFileTypeBlockSpecial: String let NSFileTypeUnknown: String

    Objective-C

    NSString * const NSFileTypeDirectory; NSString * const NSFileTypeRegular; NSString * const NSFileTypeSymbolicLink; NSString * const NSFileTypeSocket; NSString * const NSFileTypeCharacterSpecial; NSString * const NSFileTypeBlockSpecial; NSString * const NSFileTypeUnknown;

    Constants

    • NSFileTypeDirectory

      NSFileTypeDirectory

      Directory

      Available in iOS 2.0 and later.

    • NSFileTypeRegular

      NSFileTypeRegular

      Regular file

      Available in iOS 2.0 and later.

    • NSFileTypeSymbolicLink

      NSFileTypeSymbolicLink

      Symbolic link

      Available in iOS 2.0 and later.

    • NSFileTypeSocket

      NSFileTypeSocket

      Socket

      Available in iOS 2.0 and later.

    • NSFileTypeCharacterSpecial

      NSFileTypeCharacterSpecial

      Character special file

      Available in iOS 2.0 and later.

    • NSFileTypeBlockSpecial

      NSFileTypeBlockSpecial

      Block special file

      Available in iOS 2.0 and later.

    • NSFileTypeUnknown

      NSFileTypeUnknown

      Unknown

      Available in iOS 2.0 and later.

  • Keys to access the file attribute values contained in the dictionary object returned from the attributesOfFileSystemForPath:error: method.

    Declaration

    Swift

    let NSFileSystemSize: String let NSFileSystemFreeSize: String let NSFileSystemNodes: String let NSFileSystemFreeNodes: String let NSFileSystemNumber: String

    Objective-C

    extern NSString *NSFileSystemSize; extern NSString *NSFileSystemFreeSize; extern NSString *NSFileSystemNodes; extern NSString *NSFileSystemFreeNodes; extern NSString *NSFileSystemNumber;

    Constants

    • NSFileSystemSize

      NSFileSystemSize

      The key in a file system attribute dictionary whose value indicates the size of the file system.

      The corresponding value is an NSNumber object that specifies the size of the file system in bytes. The value is determined by statfs().

      Available in iOS 2.0 and later.

    • NSFileSystemFreeSize

      NSFileSystemFreeSize

      The key in a file system attribute dictionary whose value indicates the amount of free space on the file system.

      The corresponding value is an NSNumber object that specifies the amount of free space on the file system in bytes. The value is determined by statfs().

      Available in iOS 2.0 and later.

    • NSFileSystemNodes

      NSFileSystemNodes

      The key in a file system attribute dictionary whose value indicates the number of nodes in the file system.

      The corresponding value is an NSNumber object that specifies the number of nodes in the file system.

      Available in iOS 2.0 and later.

    • NSFileSystemFreeNodes

      NSFileSystemFreeNodes

      The key in a file system attribute dictionary dictionary whose value indicates the number of free nodes in the file system.

      The corresponding value is an NSNumber object that specifies the number of free nodes in the file system.

      Available in iOS 2.0 and later.

    • NSFileSystemNumber

      NSFileSystemNumber

      The key in a file system attribute dictionary dictionary whose value indicates the filesystem number of the file system.

      The corresponding value is an NSNumber object that specifies the filesystem number of the file system. The value corresponds to the value of st_dev, as returned by stat(2).

      Available in iOS 2.0 and later.

  • Specifies the values that can be associated with the NSFileProtectionKey key.

    Declaration

    Swift

    let NSFileProtectionNone: String let NSFileProtectionComplete: String let NSFileProtectionCompleteUnlessOpen: String let NSFileProtectionCompleteUntilFirstUserAuthentication: String

    Objective-C

    extern NSString* const NSFileProtectionNone; extern NSString* const NSFileProtectionComplete; extern NSString* const NSFileProtectionCompleteUnlessOpen; extern NSString* const NSFileProtectionCompleteUntilFirstUserAuthentication;

    Constants

    • NSFileProtectionNone

      NSFileProtectionNone

      The file has no special protections associated with it. It can be read from or written to at any time.

      Available in iOS 4.0 and later.

    • NSFileProtectionComplete

      NSFileProtectionComplete

      The file is stored in an encrypted format on disk and cannot be read from or written to while the device is locked or booting.

      Available in iOS 4.0 and later.

    • NSFileProtectionCompleteUnlessOpen

      NSFileProtectionCompleteUnlessOpen

      The file is stored in an encrypted format on disk. Files can be created while the device is locked, but once closed, cannot be opened again until the device is unlocked. If the file is opened when unlocked, you may continue to access the file normally, even if the user locks the device. There is a small performance penalty when the file is created and opened, though not when being written to or read from. This can be mitigated by changing the file protection to NSFileProtectionComplete when the device is unlocked.

      Available in iOS 5.0 and later.

    • NSFileProtectionCompleteUntilFirstUserAuthentication

      NSFileProtectionCompleteUntilFirstUserAuthentication

      The file is stored in an encrypted format on disk and cannot be accessed until after the device has booted. After the user unlocks the device for the first time, your app can access the file and continue to access it even if the user subsequently locks the device.

      Available in iOS 5.0 and later.

  • Constants indicating the relationship between a directory and an item.

    Declaration

    Swift

    enum NSURLRelationship : Int { case Contains case Same case Other }

    Objective-C

    typedef enum NSURLRelationship : NSInteger { NSURLRelationshipContains, NSURLRelationshipSame, NSURLRelationshipOther } NSURLRelationship;

    Constants

    • Contains

      NSURLRelationshipContains

      The directory contains the specified item.

      Available in iOS 8.0 and later.

    • Same

      NSURLRelationshipSame

      The directory and the item are the same. This relationship occurs when the value of the NSURLFileResourceIdentifierKey is the same for the directory and item.

      Available in iOS 8.0 and later.

    • Other

      NSURLRelationshipOther

      The directory does not contain the item and is not the same as the item.

      Available in iOS 8.0 and later.

    Import Statement

    Swift

    import Foundation

    Availability

    Available in iOS 8.0 and later.

  • Specifies the version of the Foundation framework in which NSFileManager first supported resource forks.

    Declaration

    Swift

    var NSFoundationVersionWithFileManagerResourceForkSupport: Int32 { get }

    Objective-C

    #define NSFoundationVersionWithFileManagerResourceForkSupport 412

    Constants

    • NSFoundationVersionWithFileManagerResourceForkSupport

      NSFoundationVersionWithFileManagerResourceForkSupport

      The version of the Foundation framework in which NSFileManager first supported resource forks.

      Available in iOS 2.0 and later.