File Operations Preview

Build Status Documentation Status codecov Maintenance

GitHub license GitHub contributors

A library that helps developers to easily perform file-related operations. In iOS,

We write our files mainly into three directories Documents Directory, Temporary Directory, Cache Directory

Requirements

File Operations Version 0.0.15
iOS Version 10.0+
Xcode 10+
Swift 4.2

Installation

Package Manager

Swift Package Manager is a tool for managing the distribution of Swift code. It’s integrated with the Swift build system to automate the process of downloading, compiling, and linking dependencies.

The Package Manager is included in Swift 3.0 and above.

https://github.com/rintoandrews90/FileOperations-Swift

Directory Types

DirectoryPath defines three directories which commonly used in our iOS application

  1. Documents Directory

  2. Temporary Directory

  3. Cache Directory

URL Methods

Get Document Directory URL

let documentDirectoryURL = FileOperations.getDocumentDirectoryURL()

Get Temporary Directory URL

let temporaryDirectoryURL =  FileOperations.getTemporaryDirectoryURL()

Get Cache Directory URL

let cacheDirectoryURL = FileOperations.getCacheDirectoryURL()

Directory Methods

Delete all contents of Directory Path

try? FileOperations.clearDirectory(path: .document)

Create directory in document/temp/cache directory with given file name. Method returns path of the directory created

let path = try? FileOperations.createDirectory(in: .document, direcotryName: "Image")

Create directory form given URL path. Method returns path of the directory created

let documentDirectoryURL = FileOperations.getDocumentDirectoryURL().appendingPathComponent("Images")

let path = try? FileOperations.createDirectory(with: documentDirectoryURL)

Remove directory from document/temp/cache directory with given file name

try? FileOperations.removeDirectory(by: .document, with: "Images")

Remove directory with provided URL

let documentDirectoryURL = FileOperations.getDocumentDirectoryURL().appendingPathComponent("test")

try? FileOperations.removeDirectory(with directoryURL:documentDirectoryURL)

Bundle Related Methods

Readt text file from bundle

 let fileContent = try? FileOperations.getText(form: Bundle.main, fileName: "sample")

Text File Operations

Create text file with file name and directory path

 let filePath =  try? FileOperations.createTextFile(in: .document, fileName: "About", content: "Sample Text")

Create text file form path

 let filePath =  try? FileOperations.createTextFile(with: path, content: "Sample Text")

Delete file with specified path

 let filePath =  try? FileOperations.createTextFile(with: path, content: "Sample Text")

Contributers


Description

  • Swift Tools 5.5.0
View More Packages from this Author

Dependencies

  • None
Last updated: Fri Oct 18 2024 07:07:34 GMT-0900 (Hawaii-Aleutian Daylight Time)