Skip to content

A Swift class to help save and retrieve files from iOS devices

License

Notifications You must be signed in to change notification settings

jjessel/JJJFile

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 

Repository files navigation

JJJFile

A Swift class to help save and retrieve files from iOS devices. To use, import FileSaveHelper.swift to your project.

Initialization

There are three init methods provided. The default directory is the Document directory and the default sub directory is empty.

If you don't want to specify the directory or sub directory for the file use:

let file = JJJFile(fileName: "myTextFile", fileExtension: .txt)

To specify a sub directory use:

let file = JJJFile(fileName: "myTextFile", fileExtension: .txt, subDirectory: "files")

To specify the sub directory and the directory use:

let file = JJJFile(fileName: "myTextFile", fileExtension: .txt, subDirectory: "files", directory: .documentDirectory)

Saving a File

If you want to save a text file, you have to give it content to save and the save method throws.

let textToSave = "Saved a file in Swift!"  

do {  
	try file.save(textToSave)
}
catch {
	print("There was an error saving the file: \(error)")
}

Checking if a File Exists

To check if a file exists, you use the fileExists property

Reading a File

To get the contents of a file use the getContentsOfFile like so:

do {
  let contents = try file.getContents()
}
catch {
  print("There was an error getting the contents: \(error)")
}

About

A Swift class to help save and retrieve files from iOS devices

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages