krz/libre-edit

A free and private text editor for iOS. ios privacy swift text-editor

Commit 896d36505a

896d36505ab0f8f4cd00741f9dfd33d0c69d7ec1

parent: b5a5dc8963

Verified · cmc

cmc <hello@cleberg.net> · 2024-01-14 17:12 UTC

fix: update documentation

Layout: unified · split

LibreEdit/ContentView.swift +4 −6
@@ -9,18 +9,15 @@ import SwiftUI
99import UniformTypeIdentifiers
1010
1111struct TextFile: FileDocument {
12 // tell the system we support only plain text
1312 static var readableContentTypes = [UTType.plainText]
14
15 // by default our document is empty
1613 var text = ""
1714
18 // a simple initializer that creates new, empty documents
15 // Initialize a new document
1916 init(initialText: String = "") {
2017 text = initialText
2118 }
2219
23 // this initializer loads data that has been saved previously
20 // Load an existing document
2421 init(configuration: ReadConfiguration) throws {
2522 if let data = configuration.file.regularFileContents {
2623 text = String(decoding: data, as: UTF8.self)
@@ -29,13 +26,14 @@ struct TextFile: FileDocument {
2926 }
3027 }
3128
32 // this will be called when the system wants to write our data to disk
29 // Save document data to file
3330 func fileWrapper(configuration: WriteConfiguration) throws -> FileWrapper {
3431 let data = Data(text.utf8)
3532 return FileWrapper(regularFileWithContents: data)
3633 }
3734}
3835
36// Counts all words in the opened file
3937func countWords(text: String) -> Int {
4038 let words = text.split { $0 == " " || $0.isNewline }
4139 return words.count