Skip to content

Commit

Permalink
Added alert if a sync detected an unknown model version.
Browse files Browse the repository at this point in the history
  • Loading branch information
drewmccormack committed Dec 25, 2024
1 parent 06d05c5 commit 28509d1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
11 changes: 9 additions & 2 deletions Samples/Forkers/Forkers/Models/Store.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Store {
private typealias RepoType = AtomicRepository<Forkers>
private let repo: RepoType
private let forkedModel: ForkedResource<RepoType>
private let cloudKitExchange: CloudKitExchange<RepoType>
private var cloudKitExchange: CloudKitExchange<RepoType>!

private static let repoDirURL: URL = FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask).first!
private static let repoFileURL: URL = repoDirURL.appendingPathComponent("Forkers.json")
Expand All @@ -52,6 +52,8 @@ class Store {
}
}

var showUpgradeAlert = false

init() throws {
// Reads repo from disk if it exists, otherwise creates it anew
repo = try AtomicRepository(managedFileURL: Self.repoFileURL)
Expand All @@ -72,7 +74,12 @@ class Store {
try forkedModel.syncMain(with: [.ui, .editingForker])

// Setup CloudKitExchange
cloudKitExchange = try .init(id: "Forkers", forkedResource: forkedModel)
cloudKitExchange = try .init(id: "Forkers",
forkedResource: forkedModel,
unknownModelVersionHandler: { [weak self] error in
self?.showUpgradeAlert = true
}
)

// Set displayed forkers to what is in the repo
displayedForkers = uiForkers
Expand Down
6 changes: 6 additions & 0 deletions Samples/Forkers/Forkers/Views/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ struct ContentView: View {
@State var editorConfig = EditorConfig()

var body: some View {
@Bindable var store = store
NavigationStack {
List {
ForEach(store.displayedForkers) { forker in
Expand Down Expand Up @@ -63,6 +64,11 @@ struct ContentView: View {
}
}
}
.alert("Update Required", isPresented: $store.showUpgradeAlert) {
Button("OK", role: .cancel) { }
} message: {
Text("Please upgrade to the latest version of the app to continue syncing.")
}
}
}
}

0 comments on commit 28509d1

Please sign in to comment.