FileManager

class FileManager : NSObject
  • SwifterSwift: Read from a JSON file at a given path.

    Throws

    Throws any errors thrown by Data creation or JSON serialization.

    Declaration

    Swift

    func jsonFromFile(
        atPath path: String,
        readingOptions: JSONSerialization.ReadingOptions = .allowFragments) throws -> [String: Any]?

    Parameters

    path

    JSON file path.

    options

    JSONSerialization reading options.

    Return Value

    Optional dictionary.

  • SwifterSwift: Read from a JSON file with a given filename.

    Throws

    Throws any errors thrown by Data creation or JSON serialization.

    Declaration

    Swift

    func jsonFromFile(
        withFilename filename: String,
        at bundleClass: AnyClass? = nil,
        readingOptions: JSONSerialization.ReadingOptions = .allowFragments) throws -> [String: Any]?

    Parameters

    filename

    File to read.

    bundleClass

    Bundle where the file is associated.

    readingOptions

    JSONSerialization reading options.

    Return Value

    Optional dictionary.

  • Creates a unique directory for saving temporary files.

    The directory can be used to create multiple temporary files used for a common purpose.

    let tempDirectory = try fileManager.createTemporaryDirectory()
    let tempFile1URL = tempDirectory.appendingPathComponent(ProcessInfo().globallyUniqueString)
    let tempFile2URL = tempDirectory.appendingPathComponent(ProcessInfo().globallyUniqueString)
    

    Throws

    An error if a temporary directory cannot be found or created.

    Declaration

    Swift

    func createTemporaryDirectory() throws -> URL

    Return Value

    A URL to a new directory for saving temporary files.