From 896d36505ab0f8f4cd00741f9dfd33d0c69d7ec1 Mon Sep 17 00:00:00 2001 From: Christian Cleberg Date: Sun, 14 Jan 2024 11:12:07 -0600 Subject: fix: update documentation --- LibreEdit/ContentView.swift | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'LibreEdit') 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 -- cgit v1.2.3-70-g09d2