Skip to content

Commit 5e83a75

Browse files
Add Example App (#237)
1 parent 0816105 commit 5e83a75

File tree

20 files changed

+972
-13
lines changed

20 files changed

+972
-13
lines changed

Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample.xcodeproj/project.pbxproj

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

Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample.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.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
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>IDEDidComputeMac32BitWarning</key>
6+
<true/>
7+
</dict>
8+
</plist>

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

Lines changed: 86 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "mac",
5+
"scale" : "1x",
6+
"size" : "16x16"
7+
},
8+
{
9+
"idiom" : "mac",
10+
"scale" : "2x",
11+
"size" : "16x16"
12+
},
13+
{
14+
"idiom" : "mac",
15+
"scale" : "1x",
16+
"size" : "32x32"
17+
},
18+
{
19+
"idiom" : "mac",
20+
"scale" : "2x",
21+
"size" : "32x32"
22+
},
23+
{
24+
"idiom" : "mac",
25+
"scale" : "1x",
26+
"size" : "128x128"
27+
},
28+
{
29+
"idiom" : "mac",
30+
"scale" : "2x",
31+
"size" : "128x128"
32+
},
33+
{
34+
"idiom" : "mac",
35+
"scale" : "1x",
36+
"size" : "256x256"
37+
},
38+
{
39+
"idiom" : "mac",
40+
"scale" : "2x",
41+
"size" : "256x256"
42+
},
43+
{
44+
"idiom" : "mac",
45+
"scale" : "1x",
46+
"size" : "512x512"
47+
},
48+
{
49+
"idiom" : "mac",
50+
"scale" : "2x",
51+
"size" : "512x512"
52+
}
53+
],
54+
"info" : {
55+
"author" : "xcode",
56+
"version" : 1
57+
}
58+
}
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+
}
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+
// CodeEditSourceEditorExampleApp.swift
3+
// CodeEditSourceEditorExample
4+
//
5+
// Created by Khan Winter on 2/24/24.
6+
//
7+
8+
import SwiftUI
9+
10+
@main
11+
struct CodeEditSourceEditorExampleApp: App {
12+
var body: some Scene {
13+
DocumentGroup(newDocument: CodeEditSourceEditorExampleDocument()) { file in
14+
ContentView(document: file.$document, fileURL: file.fileURL)
15+
}
16+
}
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//
2+
// CodeEditSourceEditorExampleDocument.swift
3+
// CodeEditSourceEditorExample
4+
//
5+
// Created by Khan Winter on 2/24/24.
6+
//
7+
8+
import SwiftUI
9+
import UniformTypeIdentifiers
10+
11+
struct CodeEditSourceEditorExampleDocument: FileDocument {
12+
var text: String
13+
14+
init(text: String = "") {
15+
self.text = text
16+
}
17+
18+
static var readableContentTypes: [UTType] {
19+
[
20+
.sourceCode,
21+
.plainText,
22+
.delimitedText,
23+
.script
24+
]
25+
}
26+
27+
init(configuration: ReadConfiguration) throws {
28+
guard let data = configuration.file.regularFileContents,
29+
let string = String(data: data, encoding: .utf8)
30+
else {
31+
throw CocoaError(.fileReadCorruptFile)
32+
}
33+
text = string
34+
}
35+
36+
func fileWrapper(configuration: WriteConfiguration) throws -> FileWrapper {
37+
let data = text.data(using: .utf8)!
38+
return .init(regularFileWithContents: data)
39+
}
40+
}

0 commit comments

Comments
 (0)