Meshtastic-Apple/Meshtastic/Export/CsvDocument.swift
2025-04-27 14:04:47 -07:00

35 lines
716 B
Swift

//
// CsvDocument.swift
// Meshtastic
//
// Copyright(c) Garth Vander Houwen 7/15/22.
//
import SwiftUI
import UniformTypeIdentifiers
struct CsvDocument: FileDocument {
static var readableContentTypes = [UTType.commaSeparatedText]
@State var csvData: String
init(emptyCsv: String = "" ) {
csvData = emptyCsv
}
init(configuration: ReadConfiguration) throws {
if let data = configuration.file.regularFileContents {
csvData = String(data: data, encoding: .utf8) ?? ""
} else {
throw CocoaError(.fileReadCorruptFile)
}
}
func fileWrapper(configuration: WriteConfiguration) throws -> FileWrapper {
let data = Data(csvData.utf8)
return FileWrapper(regularFileWithContents: data)
}
}