Skip to content
This repository was archived by the owner on Oct 24, 2025. It is now read-only.

Commit 9c1a48d

Browse files
committed
ios example finish
1 parent 8de1102 commit 9c1a48d

File tree

15 files changed

+559
-191
lines changed

15 files changed

+559
-191
lines changed

AsyncStorageSQLiteKMP/SQLiteStorageKMP.xcframework/Info.plist

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,34 +10,34 @@
1010
<key>DebugSymbolsPath</key>
1111
<string>dSYMs</string>
1212
<key>LibraryIdentifier</key>
13-
<string>ios-arm64</string>
13+
<string>ios-arm64_x86_64-simulator</string>
1414
<key>LibraryPath</key>
1515
<string>SQLiteStorageKMP.framework</string>
1616
<key>SupportedArchitectures</key>
1717
<array>
1818
<string>arm64</string>
19+
<string>x86_64</string>
1920
</array>
2021
<key>SupportedPlatform</key>
2122
<string>ios</string>
23+
<key>SupportedPlatformVariant</key>
24+
<string>simulator</string>
2225
</dict>
2326
<dict>
2427
<key>BinaryPath</key>
2528
<string>SQLiteStorageKMP.framework/SQLiteStorageKMP</string>
2629
<key>DebugSymbolsPath</key>
2730
<string>dSYMs</string>
2831
<key>LibraryIdentifier</key>
29-
<string>ios-arm64_x86_64-simulator</string>
32+
<string>ios-arm64</string>
3033
<key>LibraryPath</key>
3134
<string>SQLiteStorageKMP.framework</string>
3235
<key>SupportedArchitectures</key>
3336
<array>
3437
<string>arm64</string>
35-
<string>x86_64</string>
3638
</array>
3739
<key>SupportedPlatform</key>
3840
<string>ios</string>
39-
<key>SupportedPlatformVariant</key>
40-
<string>simulator</string>
4141
</dict>
4242
</array>
4343
<key>CFBundlePackageType</key>

samples/ios/iosExample.xcodeproj/project.pbxproj

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@
1010
058557BB273AAA24004C7B11 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 058557BA273AAA24004C7B11 /* Assets.xcassets */; };
1111
058557D9273AAEEB004C7B11 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 058557D8273AAEEB004C7B11 /* Preview Assets.xcassets */; };
1212
2152FB042600AC8F00CF470E /* iOSApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2152FB032600AC8F00CF470E /* iOSApp.swift */; };
13-
7555FF83242A565900829871 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7555FF82242A565900829871 /* ContentView.swift */; };
1413
DFB106835B31169EA75F74AA /* Pods_iosExample.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0AC38B36598A128984C6C459 /* Pods_iosExample.framework */; };
1514
E231C3C72B74355C00A54F92 /* DatabaseSelectorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E231C3C62B74355C00A54F92 /* DatabaseSelectorView.swift */; };
1615
E231C3C92B74359500A54F92 /* BasicPage.swift in Sources */ = {isa = PBXBuildFile; fileRef = E231C3C82B74359500A54F92 /* BasicPage.swift */; };
17-
E231C3CB2B74361800A54F92 /* BasicCRUDView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E231C3CA2B74361800A54F92 /* BasicCRUDView.swift */; };
16+
E231C3CB2B74361800A54F92 /* BasicView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E231C3CA2B74361800A54F92 /* BasicView.swift */; };
17+
E2AA69CE2B7952A8008C7C44 /* KeysPage.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2AA69CD2B7952A8008C7C44 /* KeysPage.swift */; };
18+
E2AA69D22B7AB02A008C7C44 /* MultiPage.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2AA69D12B7AB02A008C7C44 /* MultiPage.swift */; };
19+
E2AA69D52B7B6E5C008C7C44 /* MergePage.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2AA69D42B7B6E5C008C7C44 /* MergePage.swift */; };
1820
/* End PBXBuildFile section */
1921

2022
/* Begin PBXFileReference section */
@@ -24,12 +26,14 @@
2426
2152FB032600AC8F00CF470E /* iOSApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = iOSApp.swift; sourceTree = "<group>"; };
2527
2ADDB205B53B25DB6CD2809F /* Pods-iosExample.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-iosExample.debug.xcconfig"; path = "Target Support Files/Pods-iosExample/Pods-iosExample.debug.xcconfig"; sourceTree = "<group>"; };
2628
7555FF7B242A565900829871 /* iosExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = iosExample.app; sourceTree = BUILT_PRODUCTS_DIR; };
27-
7555FF82242A565900829871 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
2829
7555FF8C242A565B00829871 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
2930
9D57C0B1986FECE7BF0E1B51 /* Pods-iosExample.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-iosExample.release.xcconfig"; path = "Target Support Files/Pods-iosExample/Pods-iosExample.release.xcconfig"; sourceTree = "<group>"; };
3031
E231C3C62B74355C00A54F92 /* DatabaseSelectorView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DatabaseSelectorView.swift; sourceTree = "<group>"; };
3132
E231C3C82B74359500A54F92 /* BasicPage.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BasicPage.swift; sourceTree = "<group>"; };
32-
E231C3CA2B74361800A54F92 /* BasicCRUDView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BasicCRUDView.swift; sourceTree = "<group>"; };
33+
E231C3CA2B74361800A54F92 /* BasicView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BasicView.swift; sourceTree = "<group>"; };
34+
E2AA69CD2B7952A8008C7C44 /* KeysPage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeysPage.swift; sourceTree = "<group>"; };
35+
E2AA69D12B7AB02A008C7C44 /* MultiPage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MultiPage.swift; sourceTree = "<group>"; };
36+
E2AA69D42B7B6E5C008C7C44 /* MergePage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MergePage.swift; sourceTree = "<group>"; };
3337
/* End PBXFileReference section */
3438

3539
/* Begin PBXFrameworksBuildPhase section */
@@ -82,9 +86,11 @@
8286
7555FF7D242A565900829871 /* iosExample */ = {
8387
isa = PBXGroup;
8488
children = (
89+
E2AA69D32B7B6E52008C7C44 /* Merge */,
90+
E2AA69CF2B7AB018008C7C44 /* Multi */,
91+
E2AA69CC2B79529C008C7C44 /* Keys */,
8592
E231C3C52B74354000A54F92 /* Basic */,
8693
058557BA273AAA24004C7B11 /* Assets.xcassets */,
87-
7555FF82242A565900829871 /* ContentView.swift */,
8894
7555FF8C242A565B00829871 /* Info.plist */,
8995
2152FB032600AC8F00CF470E /* iOSApp.swift */,
9096
058557D7273AAEEB004C7B11 /* Preview Content */,
@@ -97,11 +103,35 @@
97103
children = (
98104
E231C3C82B74359500A54F92 /* BasicPage.swift */,
99105
E231C3C62B74355C00A54F92 /* DatabaseSelectorView.swift */,
100-
E231C3CA2B74361800A54F92 /* BasicCRUDView.swift */,
106+
E231C3CA2B74361800A54F92 /* BasicView.swift */,
101107
);
102108
path = Basic;
103109
sourceTree = "<group>";
104110
};
111+
E2AA69CC2B79529C008C7C44 /* Keys */ = {
112+
isa = PBXGroup;
113+
children = (
114+
E2AA69CD2B7952A8008C7C44 /* KeysPage.swift */,
115+
);
116+
path = Keys;
117+
sourceTree = "<group>";
118+
};
119+
E2AA69CF2B7AB018008C7C44 /* Multi */ = {
120+
isa = PBXGroup;
121+
children = (
122+
E2AA69D12B7AB02A008C7C44 /* MultiPage.swift */,
123+
);
124+
path = Multi;
125+
sourceTree = "<group>";
126+
};
127+
E2AA69D32B7B6E52008C7C44 /* Merge */ = {
128+
isa = PBXGroup;
129+
children = (
130+
E2AA69D42B7B6E5C008C7C44 /* MergePage.swift */,
131+
);
132+
path = Merge;
133+
sourceTree = "<group>";
134+
};
105135
FDD7D045D71C07FF996583FB /* Frameworks */ = {
106136
isa = PBXGroup;
107137
children = (
@@ -224,10 +254,12 @@
224254
isa = PBXSourcesBuildPhase;
225255
buildActionMask = 2147483647;
226256
files = (
257+
E2AA69D22B7AB02A008C7C44 /* MultiPage.swift in Sources */,
258+
E2AA69CE2B7952A8008C7C44 /* KeysPage.swift in Sources */,
227259
2152FB042600AC8F00CF470E /* iOSApp.swift in Sources */,
228260
E231C3C72B74355C00A54F92 /* DatabaseSelectorView.swift in Sources */,
229-
7555FF83242A565900829871 /* ContentView.swift in Sources */,
230-
E231C3CB2B74361800A54F92 /* BasicCRUDView.swift in Sources */,
261+
E231C3CB2B74361800A54F92 /* BasicView.swift in Sources */,
262+
E2AA69D52B7B6E5C008C7C44 /* MergePage.swift in Sources */,
231263
E231C3C92B74359500A54F92 /* BasicPage.swift in Sources */,
232264
);
233265
runOnlyForDeploymentPostprocessing = 0;

samples/ios/iosExample/Basic/BasicPage.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ struct BasicPage: View {
2020
if let database {
2121
VStack {
2222
Divider()
23-
BasicCRUDView(db: database)
23+
BasicView(db: database)
2424
}.id(database.name)
2525

2626
}

samples/ios/iosExample/Basic/BasicCRUDView.swift renamed to samples/ios/iosExample/Basic/BasicView.swift

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ import SwiftUI
1010
import AsyncStorageSQLiteKMP
1111

1212

13-
struct BasicCRUDView: View {
13+
private let KEY = "random"
14+
15+
struct BasicView: View {
1416
internal var db: AsyncStorageSQLite
1517

1618
@State var value: String?
@@ -22,32 +24,31 @@ struct BasicCRUDView: View {
2224
}
2325

2426
func saveRandom() {
25-
let entry = Entry(key: "random", value: String(Int.random(in: 1...100)))
27+
let entry = Entry(key: KEY, value: String(Int.random(in: 1...100)))
2628
Task {
2729
try await db.write(entry: entry)
2830
}
2931
}
3032

3133
func readRandom() {
3234
Task {
33-
let result = try await db.read(key: "random")
35+
let result = try await db.read(key: KEY)
3436
value = result.value
3537
}
3638
}
3739

3840
func deleteRandom() {
3941
Task {
40-
try await db.remove(key: "random")
42+
try await db.remove(key: KEY)
4143
}
4244
}
4345

4446
func onAppear() async {
45-
print("on appear")
4647
do {
47-
for try await updates in db.readAsFlow(keys: ["random"]) {
48-
print("updated for \(updates)")
49-
let result = try await db.read(key: "random")
50-
timelineChanges.append(result.value ?? nil)
48+
for try await updates in db.readAsFlow(keys: [KEY]) {
49+
if let entry = updates.first(where: {$0.key == KEY}) {
50+
timelineChanges.append(entry.value)
51+
}
5152
}
5253
} catch {
5354
print("error \(error)")
@@ -69,13 +70,26 @@ struct BasicCRUDView: View {
6970
.border(/*@START_MENU_TOKEN@*/Color.black/*@END_MENU_TOKEN@*/)
7071
}.frame(maxWidth: .infinity).padding()
7172

72-
(Text("value: ") + Text(value ?? "nil").fontWeight(.bold))
73-
VStack {
74-
Text("value changes in time:").fontWeight(.bold)
75-
ForEach(0..<timelineChanges.count, id: \.self) { index in
76-
Text("Updated to \(timelineChanges[index] ?? "nil")")
73+
(Text("current value: ") + Text(value ?? "nil").fontWeight(.bold))
74+
75+
List {
76+
Section {
77+
ForEach(0..<timelineChanges.count, id: \.self) { index in
78+
Text("Updated to \(timelineChanges[index] ?? "nil")")
79+
}
80+
} header: {
81+
Label(
82+
title: { Text("value changes in time:").fontWeight(.bold) },
83+
icon: { Image(systemName: "trash") }
84+
).onTapGesture {
85+
timelineChanges = []
86+
}
87+
7788
}
78-
}.padding()
89+
90+
}.listStyle(.grouped)
91+
92+
7993
}.task {
8094
let _ = await onAppear()
8195
}
@@ -85,5 +99,5 @@ struct BasicCRUDView: View {
8599

86100

87101
#Preview {
88-
BasicCRUDView(db: AsyncStorageSQLite(name: "preview"))
102+
BasicView(db: AsyncStorageSQLite(name: "preview"))
89103
}

samples/ios/iosExample/ContentView.swift

Lines changed: 0 additions & 76 deletions
This file was deleted.
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import SwiftUI
2+
import AsyncStorageSQLiteKMP
3+
4+
struct KeysPage: View {
5+
6+
let db = AsyncStorageSQLite(name: "keys.db")
7+
8+
@State var keys: [String] = []
9+
10+
init() {}
11+
12+
func addRandomKey() {
13+
let key = "key-\(Int.random(in: 1...10000))"
14+
Task {
15+
let entry = Entry(key: key, value: "random-value-\(key)")
16+
try await db.write(entry: entry)
17+
}
18+
}
19+
20+
21+
func onAppear() async {
22+
do {
23+
for try await updated in db.readKeysAsFlow() {
24+
keys = updated
25+
}
26+
} catch {
27+
print("error reading keys \(error)")
28+
}
29+
}
30+
31+
func onDelete(_ index: Int) {
32+
let key = keys[index]
33+
Task {
34+
try await db.remove(key:key)
35+
}
36+
}
37+
38+
var body: some View {
39+
VStack {
40+
Button("Add entry", action: addRandomKey)
41+
42+
List {
43+
Section {
44+
ForEach(0..<keys.count, id: \.self) { index in
45+
Label(keys[index], systemImage: "trash").imageScale(.small)
46+
.onTapGesture(perform: {
47+
onDelete(index)
48+
})
49+
}
50+
} header: {
51+
Text("Keys available")
52+
}
53+
}
54+
}.task {
55+
await onAppear()
56+
}
57+
}
58+
}
59+
60+
61+
#Preview {
62+
KeysPage()
63+
}

0 commit comments

Comments
 (0)