Skip to content

Commit 4b1db0f

Browse files
committed
Initial Commit
0 parents  commit 4b1db0f

File tree

15 files changed

+930
-0
lines changed

15 files changed

+930
-0
lines changed

OpenAIAPIUsage.xcodeproj/project.pbxproj

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

OpenAIAPIUsage.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.
Lines changed: 8 additions & 0 deletions
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>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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>SchemeUserState</key>
6+
<dict>
7+
<key>OpenAIAPIUsage.xcscheme_^#shared#^_</key>
8+
<dict>
9+
<key>orderHint</key>
10+
<integer>0</integer>
11+
</dict>
12+
</dict>
13+
</dict>
14+
</plist>
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: 58 additions & 0 deletions
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+
}

OpenAIAPIUsage/ContentView.swift

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
//
2+
// ContentView.swift
3+
// OpenAIAPIUsage
4+
//
5+
// Created by Liang on 20/02/2024.
6+
//
7+
8+
import SwiftUI
9+
import SwiftData
10+
11+
struct ContentView: View {
12+
@Environment(\.modelContext) private var modelContext
13+
@Query private var items: [Item]
14+
15+
var body: some View {
16+
NavigationSplitView {
17+
List {
18+
ForEach(items) { item in
19+
NavigationLink {
20+
Text("Item at \(item.timestamp, format: Date.FormatStyle(date: .numeric, time: .standard))")
21+
} label: {
22+
Text(item.timestamp, format: Date.FormatStyle(date: .numeric, time: .standard))
23+
}
24+
}
25+
.onDelete(perform: deleteItems)
26+
}
27+
.navigationSplitViewColumnWidth(min: 180, ideal: 200)
28+
.toolbar {
29+
ToolbarItem {
30+
Button(action: addItem) {
31+
Label("Add Item", systemImage: "plus")
32+
}
33+
}
34+
}
35+
} detail: {
36+
Text("Select an item")
37+
}
38+
}
39+
40+
private func addItem() {
41+
withAnimation {
42+
let newItem = Item(timestamp: Date())
43+
modelContext.insert(newItem)
44+
}
45+
}
46+
47+
private func deleteItems(offsets: IndexSet) {
48+
withAnimation {
49+
for index in offsets {
50+
modelContext.delete(items[index])
51+
}
52+
}
53+
}
54+
}
55+
56+
#Preview {
57+
ContentView()
58+
.modelContainer(for: Item.self, inMemory: true)
59+
}

OpenAIAPIUsage/Item.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//
2+
// Item.swift
3+
// OpenAIAPIUsage
4+
//
5+
// Created by Liang on 20/02/2024.
6+
//
7+
8+
import Foundation
9+
import SwiftData
10+
11+
@Model
12+
final class Item {
13+
var timestamp: Date
14+
15+
init(timestamp: Date) {
16+
self.timestamp = timestamp
17+
}
18+
}
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-only</key>
8+
<true/>
9+
</dict>
10+
</plist>

0 commit comments

Comments
 (0)