krz/libre-edit

A free and private text editor for iOS.

clone: git clone https://gitbay.org/krz/libre-edit.git

896d36505ab0f8f4cd00741f9dfd33d0c69d7ec1

verified · cmc

author: Christian Cleberg <hello@cleberg.net> · 2024-01-14T17:12:07Z

fix: update documentation
 LibreEdit/ContentView.swift | 10 ++++------
 1 file 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