Erfassung von „objectIDNotifications“ mit dem nicht sendbaren Typ „[Notification]“ in einem „@Sendable“-AbschlussIOS

Programmierung für iOS
Anonymous
 Erfassung von „objectIDNotifications“ mit dem nicht sendbaren Typ „[Notification]“ in einem „@Sendable“-Abschluss

Post by Anonymous »

Ich verwende Swift5 und SwiftUI und erstelle eine App, die auf CloudKit basiert.
Ich habe die Funktion zum Zusammenführen von Daten aus iCloud erstellt und sie scheint gut zu funktionieren. Aber ich erhalte immer eine Warnung wie „Erfassung von ‚objectIDNotifications‘ mit nicht sendbarem Typ ‚[Notification]‘ in einem ‚@Sendable‘-Abschluss“. Mein Code bezieht sich im Wesentlichen auf Apples Demo
Mein Code:

Code: Select all

extension AppState {

private func mergeRemoteChanges(_ notification: Notification) {
guard let transactions = notification.userInfo?[UserInfoKey.transactions] as? [NSPersistentHistoryTransaction] else {
return
}

let objectIDNotifications = transactions.compactMap { $0.objectIDNotification() }

let viewContext = PersistenceController.shared.persistentContainer.viewContext

viewContext.perform {
objectIDNotifications.forEach { changes in // warning here
viewContext.mergeChanges(fromContextDidSave: changes)
AppLog.data.trace("Merged remote changes")
}
}
}

}
Apples Code:

Code: Select all

  func photoTransactions(from notification: Notification) -> [NSPersistentHistoryTransaction] {
var results = [NSPersistentHistoryTransaction]()
if let transactions = notification.userInfo?[UserInfoKey.transactions] as? [NSPersistentHistoryTransaction] {
let photoEntityName = Photo.entity().name
for transaction in transactions where transaction.changes != nil {
for change in transaction.changes! where change.changedObjectID.entity.name == photoEntityName {
results.append(transaction)
break // Jump to the next transaction.
}
}
}
return results
}

func mergeTransactions(_ transactions: [NSPersistentHistoryTransaction], to context: NSManagedObjectContext) {
context.perform {
for transaction in transactions {
context.mergeChanges(fromContextDidSave: transaction.objectIDNotification())
}
}
}

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post