I am trying to understand Swift's Actors, but failed. I am playing around with the following example.
I want to setup a LocalStore
that uses an NSPersistentContainer
.
The struct LocalStore
should be used by a StoreManager
declared as
actor StoreManager {
private let localStore = LocalStore()
init() {
localStore.test()
}
}
LocalStore
is declared as
import CoreData
import Foundation
struct LocalStore: Sendable {
private let localPersistentContainer = NSPersistentContainer()
func test() {
print("test")
}
}
Here I get 2 compiler errors, shown here as comments:
import CoreData // Add '@_predatesConcurrency' to suppress 'Sendable'-related warnings from module 'CoreData'
private let localPersistentContainer = NSPersistentContainer() // Stored property 'localPersistentContainer' of 'Sendable'-conforming struct 'LocalStore' has non-sendable type 'NSPersistentContainer'
I neither know if it is save or advisable to suppress 'Sendable'-related warnings from module 'CoreData', nor what to do with the non-sendable type 'NSPersistentContainer'.
Any help is welcome.