From 46681d36673863cf6eb2b4395a64a0e0f39c3c18 Mon Sep 17 00:00:00 2001 From: Jungpyo Hong <54448459+jphong1111@users.noreply.github.com> Date: Wed, 5 May 2021 12:19:05 -0500 Subject: [PATCH] Delete FileManageHelper.swift --- Helper/FileManageHelper.swift | 80 ----------------------------------- 1 file changed, 80 deletions(-) delete mode 100644 Helper/FileManageHelper.swift diff --git a/Helper/FileManageHelper.swift b/Helper/FileManageHelper.swift deleted file mode 100644 index 8e4b044..0000000 --- a/Helper/FileManageHelper.swift +++ /dev/null @@ -1,80 +0,0 @@ -// -// FileManageHelper.swift -// VariousManagerDemoApp -// -// Created by JungpyoHong on 4/22/21. -// - -import Foundation - -class FileManageHelper { - - static let manager = FileManageHelper() - - let useFileHandler = FileManager.default - - private init() {} - - func getDocumentDirectoryPath() -> URL { - guard let url = useFileHandler.urls(for: .documentDirectory, - in: .userDomainMask).first else { fatalError("Can't find path") } - return url - } - - func createFile(resourceName: String, fileExtension: String) { - let fileURLProject = Bundle.main.path(forResource: resourceName, ofType: fileExtension) - let folderUrl = getDocumentDirectoryPath() - let fileUrl = folderUrl.appendingPathComponent("\(resourceName).\(fileExtension)") - do { - try useFileHandler.copyItem(atPath: fileURLProject ?? "", toPath: fileUrl.path) - } catch { - print(error) - } - } - - func writeFile(fileName: String, fileType: String, text: String) { - let fileNameWithPath: String = "\(fileName).\(fileType)" - let filePath = getDocumentDirectoryPath() - let fileUrl = filePath.appendingPathComponent(fileNameWithPath) - if useFileHandler.fileExists(atPath: fileUrl.path) { - do { - guard let fileContents = useFileHandler.contents(atPath: fileUrl.path) else { return } - let fileContentsAsString = String(bytes: fileContents, encoding: .utf8) - let fullText = "\(String(describing: fileContentsAsString) ):\(text)" - guard let data = fullText.data(using: .utf8) else { return } - try data.write(to: fileUrl) - } catch { - print(error) - } - } else { - print("File is not existed") - } - } - - func readFile(filename: String, type: String) -> String { - let realFileName = "\(filename).\(type)" - let fileURLProject = getDocumentDirectoryPath() - - let fileURL = fileURLProject.appendingPathComponent(realFileName) - - do { - let fileContentsAsString = try String(contentsOf: fileURL, encoding: .utf8) - return fileContentsAsString - } catch { fatalError("no file") } - } - - func removeFile(fileName: String, fileType: String) { - let fileNameWithPath: String = "\(fileName).\(fileType)" - let filePath = getDocumentDirectoryPath() - let fileUrl = filePath.appendingPathComponent(fileNameWithPath) - if useFileHandler.fileExists(atPath: fileUrl.path) { - do { - try useFileHandler.removeItem(at: fileUrl) - } catch { - print(error) - } - } else { - print("File is not existed") - } - } -}