aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Cleberg <hello@cleberg.net>2024-01-14 11:12:07 -0600
committerChristian Cleberg <hello@cleberg.net>2024-01-14 11:12:07 -0600
commit896d36505ab0f8f4cd00741f9dfd33d0c69d7ec1 (patch)
tree0953b19f889f0b6fb41770ad70bad759bdec5f50
parentb5a5dc8963dbd73d30c188eb9f3018add76a2c06 (diff)
downloadlibre-edit-896d36505ab0f8f4cd00741f9dfd33d0c69d7ec1.tar.gz
libre-edit-896d36505ab0f8f4cd00741f9dfd33d0c69d7ec1.tar.bz2
libre-edit-896d36505ab0f8f4cd00741f9dfd33d0c69d7ec1.zip
fix: update documentation
-rw-r--r--LibreEdit/ContentView.swift10
1 files changed, 4 insertions, 6 deletions
diff --git a/LibreEdit/ContentView.swift b/LibreEdit/ContentView.swift
index 641a534..3b6d69e 100644
--- a/LibreEdit/ContentView.swift
+++ b/LibreEdit/ContentView.swift
@@ -9,18 +9,15 @@ import SwiftUI
import UniformTypeIdentifiers
struct TextFile: FileDocument {
- // tell the system we support only plain text
static var readableContentTypes = [UTType.plainText]
-
- // by default our document is empty
var text = ""
- // a simple initializer that creates new, empty documents
+ // Initialize a new document
init(initialText: String = "") {
text = initialText
}
- // this initializer loads data that has been saved previously
+ // Load an existing document
init(configuration: ReadConfiguration) throws {
if let data = configuration.file.regularFileContents {
text = String(decoding: data, as: UTF8.self)
@@ -29,13 +26,14 @@ struct TextFile: FileDocument {
}
}
- // this will be called when the system wants to write our data to disk
+ // Save document data to file
func fileWrapper(configuration: WriteConfiguration) throws -> FileWrapper {
let data = Data(text.utf8)
return FileWrapper(regularFileWithContents: data)
}
}
+// Counts all words in the opened file
func countWords(text: String) -> Int {
let words = text.split { $0 == " " || $0.isNewline }
return words.count