FileManager

class FileManager : NSObject

This extension adds some useful functions to FileManager.

  • Get the path for a PathType.

    Declaration

    Swift

    public func pathFor(_ path: PathType) -> String?

    Parameters

    path

    Path type.

    Return Value

    Returns the path type String.

  • Save a file with given content.

    Throws

    write(toFile:, atomically:, encoding:) errors.

    Declaration

    Swift

    public func save(file: String, in path: PathType, content: String) throws

    Parameters

    file

    File to be saved.

    path

    File path.

    content

    Content to be saved.

  • Read a file an returns the content as String.

    Throws

    Throws String(contentsOfFile:, encoding:) errors.

    Declaration

    Swift

    public func read(file: String, from path: PathType) throws -> String?

    Parameters

    file

    File to be read.

    path

    File path.

    Return Value

    Returns the content of the file a String.

  • Undocumented

    Declaration

    Swift

    @discardableResult
    public func savePlist(object: Any, in path: PathType, filename: String) -> Bool
  • Load an object from a PLIST with given filename.

    Declaration

    Swift

    public func readPlist(from path: PathType, filename: String) -> Any?

    Parameters

    path

    Path of PLIST.

    filename

    PLIST filename.

    Return Value

    Returns the loaded object.

  • Get Main Bundle path for a filename. If no file is specified, the main bundle path will be returned.

    Declaration

    Swift

    public func mainBundlePath(file: String = "") -> String?

    Parameters

    file

    Filename.

    Return Value

    Returns the path as a String.

  • Get Documents path for a filename.

    Declaration

    Swift

    public func documentsPath(file: String = "") -> String?

    Parameters

    file

    Filename

    Return Value

    Returns the path as a String.

  • Get Library path for a filename.

    Declaration

    Swift

    public func libraryPath(file: String = "") -> String?

    Parameters

    file

    Filename

    Return Value

    Returns the path as a String.

  • Get Cache path for a filename.

    Declaration

    Swift

    public func cachePath(file: String = "") -> String?

    Parameters

    file

    Filename

    Return Value

    Returns the path as a String.

  • Get Application Support path for a filename.

    Declaration

    Swift

    public func applicationSupportPath(file: String = "") -> String?

    Parameters

    file

    Filename

    Return Value

    Returns the path as a String.

  • Get Temporary path for a filename.

    Declaration

    Swift

    public func temporaryPath(file: String = "") -> String?

    Parameters

    file

    Filename.

    Return Value

    Returns the path as a String.

  • Returns the file size.

    Throws

    Throws FileManager.default.attributesOfItem(atPath:) errors.

    Declaration

    Swift

    public func size(file: String, from path: PathType) throws -> Float?

    Parameters

    file

    Filename.

    path

    Path of the file.

    Return Value

    Returns the file size.

  • Delete a file with the given filename.

    Throws

    Throws FileManager.default.removeItem(atPath:) errors.

    Declaration

    Swift

    public func delete(file: String, from path: PathType) throws

    Parameters

    file

    File to delete.

    path

    Path of the file.

  • Move a file from a path to another.

    Throws

    Throws FileManager.default.moveItem(atPath:, toPath:) and BFKitError errors.

    Declaration

    Swift

    public func move(file: String, from origin: PathType, to destination: PathType) throws

    Parameters

    file

    Filename to move.

    origin

    Origin path of the file.

    destination

    Destination path of the file.

    Return Value

    Returns true if the operation was successful, otherwise false.

  • Copy a file into another path.

    Throws

    Throws FileManager.default.copyItem(atPath:, toPath:) and BFKitError errors.

    Declaration

    Swift

    public func copy(file: String, from origin: PathType, to destination: PathType) throws

    Parameters

    file

    Filename to copy.

    origin

    Origin path

    destination

    Destination path

    Return Value

    Returns true if the operation was successful, otherwise false.

  • Rename a file with another filename.

    Throws

    Throws FileManager.default.copyItem(atPath:, toPath:), FileManager.default.removeItem(atPath:, toPath:) and BFKitError errors.

    Declaration

    Swift

    public func rename(file: String, in origin: PathType, to newName: String) throws

    Parameters

    file

    Filename to rename.

    origin

    Origin path.

    newName

    New filename.

    Return Value

    Returns true if the operation was successful, otherwise false.

  • Undocumented

    Declaration

    Swift

    @discardableResult
    public func setSettings(filename: String, object: Any, forKey objKey: String) -> Bool
  • Get settings for key.

    Declaration

    Swift

    public func getSettings(filename: String, forKey: String) -> Any?

    Parameters

    filename

    Settings filename. -Settings will be automatically added.

    forKey

    Object key.

    Return Value

    Returns the object for the given key.