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