FileManager

  • Mechanica

    Returns the location of the document directory (Documents/) in the user’s home directory. The contents of this directory can be made available to the user through file sharing; therefore, his directory should only contain files that you may wish to expose to the user.

    Note

    Use this directory to store user-generated content.

    The contents of Documents directory are backed up by iTunes and iCloud.

    Declaration

    Swift

    public var userDocumentDirectory: URL?
  • Mechanica

    Returns the location of the library directory (Library/) in the user’s home directory.

    Note

    Use the Library subdirectories for any files you don’t want exposed to the user. Your app should not use these directories for user data files.

    You typically put files in one of several standard subdirectories. iOS apps commonly use the Application Support and Caches subdirectories; however, you can create custom subdirectories.

    The contents of the Library directory are backed up by iTunes and iCloud (with the exception of the Caches subdirectory).

    Declaration

    Swift

    public var userLibraryDirectory: URL?
  • Mechanica

    Returns the location of discardable cache files (Library/Caches/) in the user’s home directory.

    Note

    Put data cache files in the Library/Caches/ directory. Cache data can be used for any data that needs to persist longer than temporary data, but not as long as a support file.

    Generally speaking, the application does not require cache data to operate properly, but it can use cache data to improve performance. Examples of cache data include (but are not limited to) database cache files and transient, downloadable content.

    The contents of the Library/Caches are not backed up by iTunes and iCloud.

    Note that the system may delete the Caches/ directory to free up disk space, so your app must be able to re-create or download these files as needed.

    Important

    Sandboxed macOS apps have all their Caches directory located at a system-defined path (typically found at ~/Library/Containers/).

    Declaration

    Swift

    public var userCachesDirectory: URL?
  • Mechanica

    Returns the location of application support files (Library/Application Support/) in the user’s home directory.

    Note

    Put app-created support files in the Library/Application support/ directory.

    In general, this directory includes files that the app uses to run but that should remain hidden from the user. This directory can also include data files, configuration files, templates and modified versions of resources loaded from the app bundle.

    The contents of the Library/Application Support/ are backed up by iTunes and iCloud.

    Warning

    On macOS all content in this directory should be placed in a custom subdirectory whose name is that of your app’s bundle identifier or your company.

    Important

    Sandboxed macOS apps have all their Application Support directory located at a system-defined path (typically found at ~/Library/Containers/).

    Declaration

    Swift

    public var userApplicationSupportDirectory: URL?
  • Mechanica

    Creates and returns always a new directory in Library/Caches in the user’s home directory for discardable cache files.

    Declaration

    Swift

    public var makeNewUserCachesSubDirectory: URL?
  • Mechanica

    Returns the container directory associated with the specified security application group Identifier.

    Declaration

    Swift

    public final func containerDirectory(for groupIdentifier: String) -> URL?
  • Mechanica

    Clears all contents in a directory path; throws an error in cases of failure.

    Declaration

    Swift

    public final func clearDirectory(atPath path: String) throws

    Parameters

    path

    directory path (if it’s not a directory path, nothing is done).

  • Mechanica

    Destroys a file or a directory at a given path; throws an error in cases of failure.

    Declaration

    Swift

    public final func destroyFileOrDirectory(atPath path: String) throws

    Parameters

    path

    directory or file path.