Skip to content

Commit 09a3f21

Browse files
Add Example App (#64)
### Description - Adds an example app. Just a barebones example of how to use the `TextView` class to create a plain-text editor. - The project is set up so the package is a local, editable, dependency. This has been extremely useful in CESE, and should help when developing this package. It's also good documentation, and we can point people towards this example app if they'd like to see how to use the text view. ### Related Issues - N/A ### Checklist - [x] I read and understood the [contributing guide](https://github.com/CodeEditApp/CodeEdit/blob/main/CONTRIBUTING.md) as well as the [code of conduct](https://github.com/CodeEditApp/CodeEdit/blob/main/CODE_OF_CONDUCT.md) - [x] The issues this PR addresses are related to each other - [x] My changes generate no new warnings - [x] My code builds and runs on my machine - [x] My changes are all related to the related issue above - [x] I documented my code ### Screenshots ![Screenshot 2025-01-09 at 3 06 14 PM](https://github.com/user-attachments/assets/bc94e85d-eada-4dd0-9337-133cd79ede9e)
1 parent 41ea36f commit 09a3f21

File tree

13 files changed

+746
-0
lines changed

13 files changed

+746
-0
lines changed

Example/CodeEditTextViewExample/CodeEditTextViewExample.xcodeproj/project.pbxproj

Lines changed: 408 additions & 0 deletions
Large diffs are not rendered by default.

Example/CodeEditTextViewExample/CodeEditTextViewExample.xcodeproj/project.xcworkspace/contents.xcworkspacedata

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/CodeEditTextViewExample/CodeEditTextViewExample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 41 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"colors" : [
3+
{
4+
"idiom" : "universal"
5+
}
6+
],
7+
"info" : {
8+
"author" : "xcode",
9+
"version" : 1
10+
}
11+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "universal",
5+
"platform" : "ios",
6+
"size" : "1024x1024"
7+
},
8+
{
9+
"appearances" : [
10+
{
11+
"appearance" : "luminosity",
12+
"value" : "dark"
13+
}
14+
],
15+
"idiom" : "universal",
16+
"platform" : "ios",
17+
"size" : "1024x1024"
18+
},
19+
{
20+
"appearances" : [
21+
{
22+
"appearance" : "luminosity",
23+
"value" : "tinted"
24+
}
25+
],
26+
"idiom" : "universal",
27+
"platform" : "ios",
28+
"size" : "1024x1024"
29+
}
30+
],
31+
"info" : {
32+
"author" : "xcode",
33+
"version" : 1
34+
}
35+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"info" : {
3+
"author" : "xcode",
4+
"version" : 1
5+
}
6+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>com.apple.security.app-sandbox</key>
6+
<true/>
7+
<key>com.apple.security.files.user-selected.read-write</key>
8+
<true/>
9+
</dict>
10+
</plist>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// CodeEditTextViewExampleApp.swift
3+
// CodeEditTextViewExample
4+
//
5+
// Created by Khan Winter on 1/9/25.
6+
//
7+
8+
import SwiftUI
9+
10+
@main
11+
struct CodeEditTextViewExampleApp: App {
12+
var body: some Scene {
13+
DocumentGroup(newDocument: CodeEditTextViewExampleDocument()) { file in
14+
ContentView(document: file.$document)
15+
}
16+
}
17+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//
2+
// CodeEditTextViewExampleDocument.swift
3+
// CodeEditTextViewExample
4+
//
5+
// Created by Khan Winter on 1/9/25.
6+
//
7+
8+
import SwiftUI
9+
import UniformTypeIdentifiers
10+
11+
struct CodeEditTextViewExampleDocument: FileDocument {
12+
var text: String
13+
14+
init(text: String = "") {
15+
self.text = text
16+
}
17+
18+
static var readableContentTypes: [UTType] {
19+
[
20+
.item
21+
]
22+
}
23+
24+
init(configuration: ReadConfiguration) throws {
25+
guard let data = configuration.file.regularFileContents else {
26+
throw CocoaError(.fileReadCorruptFile)
27+
}
28+
text = String(decoding: data, as: UTF8.self)
29+
}
30+
31+
func fileWrapper(configuration: WriteConfiguration) throws -> FileWrapper {
32+
let data = Data(text.utf8)
33+
return .init(regularFileWithContents: data)
34+
}
35+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>CFBundleDocumentTypes</key>
6+
<array>
7+
<dict>
8+
<key>CFBundleTypeRole</key>
9+
<string>Editor</string>
10+
<key>LSItemContentTypes</key>
11+
<array>
12+
<string>com.example.plain-text</string>
13+
</array>
14+
<key>NSUbiquitousDocumentUserActivityType</key>
15+
<string>$(PRODUCT_BUNDLE_IDENTIFIER).exampledocument</string>
16+
</dict>
17+
</array>
18+
<key>UTImportedTypeDeclarations</key>
19+
<array>
20+
<dict>
21+
<key>UTTypeConformsTo</key>
22+
<array>
23+
<string>public.plain-text</string>
24+
</array>
25+
<key>UTTypeDescription</key>
26+
<string>Example Text</string>
27+
<key>UTTypeIdentifier</key>
28+
<string>com.example.plain-text</string>
29+
<key>UTTypeTagSpecification</key>
30+
<dict>
31+
<key>public.filename-extension</key>
32+
<array>
33+
<string>exampletext</string>
34+
</array>
35+
</dict>
36+
</dict>
37+
</array>
38+
</dict>
39+
</plist>

0 commit comments

Comments
 (0)