Skip to content

Commit 5803d52

Browse files
committed
Merge remote-tracking branch 'origin/main' into schema-change-test-failure
2 parents 01daefb + 20f2e41 commit 5803d52

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1726
-848
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
name: macOS
1515
strategy:
1616
matrix:
17-
xcode: ['26.1']
17+
xcode: ['26.2']
1818
config: ['debug', 'release']
1919
runs-on: macos-26
2020
steps:
@@ -28,7 +28,7 @@ jobs:
2828
name: Examples
2929
strategy:
3030
matrix:
31-
xcode: ['26.1']
31+
xcode: ['26.2']
3232
config: ['debug']
3333
scheme: ['Reminders', 'CaseStudies', 'SyncUps']
3434
runs-on: macos-26

Examples/CloudKitDemo/CloudKitDemoApp.swift

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,22 @@ import SwiftUI
55
@main
66
struct CloudKitDemoApp: App {
77
@UIApplicationDelegateAdaptor private var appDelegate: AppDelegate
8+
@Dependency(\.context) var context
89

910
init() {
10-
try! prepareDependencies {
11-
try $0.bootstrapDatabase()
11+
if context == .live {
12+
try! prepareDependencies {
13+
try $0.bootstrapDatabase()
14+
}
1215
}
1316
}
1417

1518
var body: some Scene {
1619
WindowGroup {
17-
NavigationStack {
18-
CountersListView()
20+
if context == .live {
21+
NavigationStack {
22+
CountersListView()
23+
}
1924
}
2025
}
2126
}

Examples/CloudKitDemo/CountersListFeature.swift

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,29 @@
11
import CloudKit
22
import SQLiteData
33
import SwiftUI
4-
import SwiftUINavigation
54

65
struct CountersListView: View {
7-
@FetchAll var counters: [Counter]
6+
@FetchAll(
7+
Counter
8+
.leftJoin(SyncMetadata.all) { $0.syncMetadataID.eq($1.id) }
9+
.select {
10+
Row.Columns(counter: $0, isShared: $1.isShared.ifnull(false))
11+
}
12+
) var rows
813
@Dependency(\.defaultDatabase) var database
14+
@Dependency(\.defaultSyncEngine) var syncEngine
15+
16+
@Selection struct Row {
17+
let counter: Counter
18+
let isShared: Bool
19+
}
920

1021
var body: some View {
1122
List {
12-
if !counters.isEmpty {
23+
if !rows.isEmpty {
1324
Section {
14-
ForEach(counters) { counter in
15-
CounterRow(counter: counter)
25+
ForEach(rows, id: \.counter.id) { row in
26+
CounterRow(row: row)
1627
.buttonStyle(.borderless)
1728
}
1829
.onDelete { indexSet in
@@ -25,10 +36,14 @@ struct CountersListView: View {
2536
.toolbar {
2637
ToolbarItem(placement: .primaryAction) {
2738
Button("Add") {
28-
withErrorReporting {
29-
try database.write { db in
30-
try Counter.insert { Counter.Draft() }
39+
Task {
40+
withErrorReporting {
41+
try database.write { db in
42+
try Counter.insert {
43+
Counter.Draft()
44+
}
3145
.execute(db)
46+
}
3247
}
3348
}
3449
}
@@ -40,7 +55,7 @@ struct CountersListView: View {
4055
withErrorReporting {
4156
try database.write { db in
4257
for index in indexSet {
43-
try Counter.find(counters[index].id).delete()
58+
try Counter.find(rows[index].counter.id).delete()
4459
.execute(db)
4560
}
4661
}
@@ -49,15 +64,18 @@ struct CountersListView: View {
4964
}
5065

5166
struct CounterRow: View {
52-
let counter: Counter
67+
let row: CountersListView.Row
5368
@State var sharedRecord: SharedRecord?
5469
@Dependency(\.defaultDatabase) var database
5570
@Dependency(\.defaultSyncEngine) var syncEngine
5671

5772
var body: some View {
5873
VStack {
5974
HStack {
60-
Text("\(counter.count)")
75+
if row.isShared {
76+
Image(systemName: "network")
77+
}
78+
Text("\(row.counter.count)")
6179
Button("-") {
6280
decrementButtonTapped()
6381
}
@@ -79,7 +97,7 @@ struct CounterRow: View {
7997

8098
func shareButtonTapped() {
8199
Task {
82-
sharedRecord = try await syncEngine.share(record: counter) { share in
100+
sharedRecord = try await syncEngine.share(record: row.counter) { share in
83101
share[CKShare.SystemFieldKey.title] = "Join my counter!"
84102
}
85103
}
@@ -88,7 +106,7 @@ struct CounterRow: View {
88106
func decrementButtonTapped() {
89107
withErrorReporting {
90108
try database.write { db in
91-
try Counter.find(counter.id).update {
109+
try Counter.find(row.counter.id).update {
92110
$0.count -= 1
93111
}
94112
.execute(db)
@@ -99,11 +117,21 @@ struct CounterRow: View {
99117
func incrementButtonTapped() {
100118
withErrorReporting {
101119
try database.write { db in
102-
try Counter.find(counter.id).update {
120+
try Counter.find(row.counter.id).update {
103121
$0.count += 1
104122
}
105123
.execute(db)
106124
}
107125
}
108126
}
109127
}
128+
129+
#Preview {
130+
let _ = try! prepareDependencies {
131+
try $0.bootstrapDatabase()
132+
try? $0.defaultDatabase.seedSampleData()
133+
}
134+
NavigationStack {
135+
CountersListView()
136+
}
137+
}

Examples/CloudKitDemo/Schema.swift

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@ nonisolated struct Counter: Identifiable {
1010

1111
extension DependencyValues {
1212
mutating func bootstrapDatabase() throws {
13-
@Dependency(\.context) var context
14-
let database = try SQLiteData.defaultDatabase()
13+
var configuration = Configuration()
14+
configuration.prepareDatabase { db in
15+
try db.attachMetadatabase()
16+
}
17+
let database = try SQLiteData.defaultDatabase(configuration: configuration)
1518
logger.debug(
1619
"""
1720
App database
@@ -44,3 +47,16 @@ extension DependencyValues {
4447
}
4548

4649
private let logger = Logger(subsystem: "CloudKitDemo", category: "Database")
50+
51+
#if DEBUG
52+
extension DatabaseWriter {
53+
func seedSampleData() throws {
54+
try write { db in
55+
try db.seed {
56+
Counter.Draft(count: 24)
57+
Counter.Draft(count: 1729)
58+
}
59+
}
60+
}
61+
}
62+
#endif

Examples/Examples.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

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

Examples/Reminders/RemindersDetail.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class RemindersDetailModel: HashableObject {
8484

8585
private func updateQuery() async {
8686
await withErrorReporting {
87-
try await $reminderRows.load(remindersQuery, animation: .default)
87+
_ = try await $reminderRows.load(remindersQuery, animation: .default)
8888
}
8989
}
9090

Examples/Reminders/RemindersLists.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,7 @@ class RemindersListsModel {
144144
#if DEBUG
145145
func seedDatabaseButtonTapped() {
146146
withErrorReporting {
147-
try database.write { db in
148-
try db.seedSampleData()
149-
}
147+
try database.seedSampleData()
150148
}
151149
}
152150
#endif
@@ -437,7 +435,8 @@ private struct ReminderGridCell: View {
437435

438436
#Preview {
439437
let _ = try! prepareDependencies {
440-
$0.defaultDatabase = try Reminders.appDatabase()
438+
try $0.bootstrapDatabase()
439+
try? $0.defaultDatabase.seedSampleData()
441440
}
442441
NavigationStack {
443442
RemindersListsView(model: RemindersListsModel())

0 commit comments

Comments
 (0)