Skip to content

Instantly share code, notes, and snippets.

@KatagiriSo
Created November 9, 2017 09:29
Show Gist options
  • Save KatagiriSo/c11fbfbf2f1ac7fbfe98adefe5ddc9c2 to your computer and use it in GitHub Desktop.
Save KatagiriSo/c11fbfbf2f1ac7fbfe98adefe5ddc9c2 to your computer and use it in GitHub Desktop.
//
// RDFile.swift
// RDFileUtil
//
// Created by KatagiriSo on 2017/11/09.
// Copyright © 2017年 rodhosSoft. All rights reserved.
//
import Foundation
class RDFile {
let fileName:String
let filePath:String
let fileURL:URL
var texts:[String] = []
func getText() -> String {
return texts.joined(separator: "\n")
}
static func createFile(fileName:String) -> RDFile {
RDFileUtil.createFile(name: fileName)
return RDFile(fileName: fileName)
}
init(fileName:String) {
self.fileName = fileName
let fm = FileManager()
let path = fm.currentDirectoryPath
self.filePath = path + "/" + fileName
self.fileURL = URL(fileURLWithPath: self.filePath)
}
@discardableResult func append(text:String) -> Self {
texts.append(text)
return self
}
func write() {
RDFileUtil.writeFile(fileName: self.fileName, content: self.getText())
}
func readFile() -> String {
return RDFileUtil.readFile(fileName: self.fileName)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment