You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
875 B
36 lines
875 B
//
|
|
// FileWriter.swift
|
|
// TournamentStats
|
|
//
|
|
// Created by Laurent Morvillier on 03/06/2019.
|
|
// Copyright © 2019 Stax River. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
enum FileError : Error {
|
|
case documentDirectoryNotFound
|
|
}
|
|
|
|
class FileUtils {
|
|
|
|
static var documentsDirectoryPath: URL? {
|
|
return FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first
|
|
}
|
|
|
|
}
|
|
|
|
class FileWriter {
|
|
|
|
static func writeToDocumentDirectory(content: String, fileName: String) throws {
|
|
|
|
if let dir = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first {
|
|
let fileURL = dir.appendingPathComponent(fileName)
|
|
try content.write(to: fileURL, atomically: false, encoding: .utf8)
|
|
} else {
|
|
throw FileError.documentDirectoryNotFound
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|