Я сталкиваюсь с проблемой, в которой 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
Доступ к модели Context за пределами иерархии просмотра, что приводит к тому, что ModelContext не сохраняет ⇐ IOS
Программируем под IOS
1740477692
Anonymous
Я сталкиваюсь с проблемой, в которой 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.
Подробнее здесь: [url]https://stackoverflow.com/questions/79464711/accesing-modelcontext-outside-of-view-hiearchy-causing-modelcontext-to-not-save[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия