Я сталкиваюсь с проблемой, в которой Swiftdata работает отлично и сохраняет мои данные, если я прокомментирую любые строки, которые Call Permonssync , но как только я попытаюсь вызовать efferationsync () , SwiftData не может сохранить любые Изменения вообще. Я передаю в ModelContext в пользовательский класс из оператора @enviroment из представления onapear . Как мне это исправить? < /P>
func performSync() async {
guard let notionService = notionService, isInitialized else { return }
// Set isSyncing on the main actor.
await MainActor.run {
isSyncing = true
}
do {
// Fetch the ideas on the main actor.
let ideas: [Idea] = try await MainActor.run {
let descriptor = FetchDescriptor()
return try modelContext.fetch(descriptor)
}
try await notionService.syncIdeas(ideas)
// Save changes on the main actor.
await MainActor.run {
try? modelContext.save()
isSyncing = false
}
} catch {
print("Sync failed: \(error)")
await MainActor.run {
isSyncing = false
}
}
}
< /code>
.onAppear{
if let paId = UserDefaults.standard.string(forKey: DefaultsKeys.parentPageId){
if !completedSetupSync{
authManager.setupSyncManager(parentPageId: paId, modelContext: modelContext)
completedSetupSync = true
}
}
}
< /code>
I was expecting the code to not effect other container changes outside the class and also be able to save changes to the context itself.
Подробнее здесь: https://stackoverflow.com/questions/794 ... o-not-save