Meshtastic-Apple/MeshtasticClient/Views/Settings/LogDocument.swift

26 lines
613 B
Swift
Raw Normal View History

import SwiftUI
import UniformTypeIdentifiers
2021-11-29 15:59:06 -08:00
struct LogDocument: FileDocument {
static var readableContentTypes: [UTType] {[.plainText]}
var logFile: String
2021-11-29 15:59:06 -08:00
init(logFile: String) {
self.logFile = logFile
}
2021-11-29 15:59:06 -08:00
init(configuration: ReadConfiguration) throws {
guard let data = configuration.file.regularFileContents,
let string = String(data: data, encoding: .utf8)
2021-11-29 15:59:06 -08:00
else {
throw CocoaError(.fileReadCorruptFile)
}
logFile = string
}
2021-11-29 15:59:06 -08:00
func fileWrapper(configuration: WriteConfiguration) throws -> FileWrapper {
return FileWrapper(regularFileWithContents: logFile.data(using: .utf8)!)
}
}