Latest 1.0.6
License MIT
Platforms osx 10.10

CI Status

Two classes for Swift3 to read and write in files more easily (inspired of Java)

It can be used in Ubuntu

Table of Contents


To use SimpliFile in your xcode project :

  • run "sudo gem install cocoapods"
  • run "pod init" in your project directory
  • add " pod ‘SimpliFile’ " in the Podfile
  • run "pod install"
  • open your project with the .xcworkspace file

To use SimpliFile in a commandline project (OSX or Ubuntu) :


  • Create the reader / the writer
  • Write
  • Read
Create the reader / the writer

In the creation of a reader or a writer, a FileError.FILE_CREATION_ERROR can be thrown.

When a FileReader or a FileWriter is creating with success, the file and all of the subdirectories are created if they don’t exist.

For the FileWriter, the append parameter specify if we append text to the file, or if we clear the file before writing.

import SimpliFile

*Available for all platforms :

The pathToDirectory parameter can be a absolute or a relative path.

If we don’t specify the pathToDirectory parameter, it will use the current directory

let writer : FileWriter = try! FileWriter(pathToDirectory: "../textFiles", fileName: "file.txt", append:true)
let reader: FileReader = try! FileReader(pathToDirectory: "../textFiles", fileName: "file.txt")

*Available for OSX (not for Ubuntu) :

The directory parameter can take all of the FileManager.SearchPathDirectory values (

The domainMask parameter can take all of the FileManager.SearchPathDomainMask values (

The default value of domainMask is .userDomainMask

let writer:FileWriter = try! FileWriter(directory: .libraryDirectory, domainMask: .userDomainMask, subDirectories: "application/textFiles", fileName: "text.txt", append: false)     //will use the file "/Users/<login>/Library/application/textFiles/text.txt"

let reader: FileReader =  try! FileReader(directory: .libraryDirectory, domainMask: .userDomainMask, subDirectories: "application/textFiles", fileName: "text.txt")

a FileError.FILE_WRITING_ERROR can be thrown when you write in a file

try! writer.write(text: "string1")    //a FileError.FILE_WRITING_ERROR can be thrown
try! writer.newLine()
try! writer.write(text: "string2")

a FileError.FILE_READING_ERROR can be thrown when you read the file

var isEmpty:Bool = try! reader.isEmptyFile())    //return true if the file is empty

//With the following methods, a FileError.FILE_READING_ERROR can be thrown
var string:String = try!    //get all of the content of the file

var ligne: String?
ligne = try! reader.readLine()     //Reading by line


SimpliFile is owned and maintained by Fl Pe ([email protected])
You can send him an email if you want to report a bug / talk to him about this module.


SimpliFile is available under the MIT license. See the LICENSE file for more info.

Latest podspec

    "name": "SimpliFile",
    "version": "1.0.6",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    "summary": "Two classes for Swift3 to read and write in files more easily (inspired of Java)",
    "homepage": "",
    "authors": {
        "FlPe": ""
    "source": {
        "git": "",
        "tag": "1.0.6"
    "platforms": {
        "osx": "10.10"
    "source_files": "SimpliFile/Classes/*.swift",
    "pushed_with_swift_version": "3.0"

Pin It on Pinterest

Share This