I'm using a core data child context to separate temporary entities from my main context, but when I pass in the main context as an environment variable, I don't have access to it in order to initialize the child context and get a 'self' used before all stored properties are initialized error
Any suggestions?
struct CreatePlayerView: View {
@State private var newPlayer: PlayerEntity
@Environment(\.managedObjectContext) private var managedObjectContext
private let childManagedObjectContext: NSManagedObjectContext
init() {
childManagedObjectContext = NSManagedObjectContext(concurrencyType: .privateQueueConcurrencyType)
\\ 'self' used before all stored properties are initialized
childManagedObjectContext.parent = managedObjectContext
newPlayer = PlayerEntity(context: childManagedObjectContext)
}
var body: some View {
EditPlayerViewDetail(
player: $newPlayer,
onDone: { player in
try? childManagedObjectContext.save()
}
)
}
}