diff options
| author | Dustin Mierau <dustin@mierau.me> | 2023-12-22 23:29:20 -0800 |
|---|---|---|
| committer | Dustin Mierau <dustin@mierau.me> | 2023-12-22 23:29:20 -0800 |
| commit | 8a2a78d62f1cb9a75fe3fc5254f76cc4ffdd26f7 (patch) | |
| tree | 3501ad6fdef17c1823055a7186509eac5dfc76b2 /Hotline/Utility | |
| parent | 141ba771eddd2e504a0f29bafd7b9f7c032b72c0 (diff) | |
Added Save Chat button to Chat toolbar.
Diffstat (limited to 'Hotline/Utility')
| -rw-r--r-- | Hotline/Utility/TextDocument.swift | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/Hotline/Utility/TextDocument.swift b/Hotline/Utility/TextDocument.swift new file mode 100644 index 0000000..3904a21 --- /dev/null +++ b/Hotline/Utility/TextDocument.swift @@ -0,0 +1,29 @@ +import Foundation +import UniformTypeIdentifiers +import SwiftUI + +struct TextFile: FileDocument { + // tell the system we support only plain text + static var readableContentTypes = [UTType.plainText, UTType.utf8PlainText] + + // by default our document is empty + var text = "" + + // a simple initializer that creates new, empty documents + init(initialText: String = "") { + text = initialText + } + + // this initializer loads data that has been saved previously + init(configuration: ReadConfiguration) throws { + if let data = configuration.file.regularFileContents { + text = String(decoding: data, as: UTF8.self) + } + } + + // this will be called when the system wants to write our data to disk + func fileWrapper(configuration: WriteConfiguration) throws -> FileWrapper { + let data = Data(text.utf8) + return FileWrapper(regularFileWithContents: data) + } +} |