Brilliant, thanks, I had tried it using another class but for some reason it didn't work, but I must have had something wrong.
Thanks again for your answer.. much appreciated
Post
Replies
Boosts
Views
Activity
hmmmm, since implementing the two classes you describe, the App no longer loads the CoreData Stack.
When using the App Delegate it did actually load and the App Worked.
Here's the Trace
2020-06-27 22:20:45.210645+1200 Sessions[73503:1020937] [error] error: No NSEntityDescriptions in any model claim the NSManagedObject subclass 'Sessions.Session' so +entity is confused. Have you loaded your NSManagedObjectModel yet ?
CoreData: error: No NSEntityDescriptions in any model claim the NSManagedObject subclass 'Sessions.Session' so +entity is confused. Have you loaded your NSManagedObjectModel yet ?
2020-06-27 22:20:45.211159+1200 Sessions[73503:1020937] [error] error: +[Sessions.Session entity] Failed to find a unique match for an NSEntityDescription to a managed object subclass
CoreData: error: +[Sessions.Session entity] Failed to find a unique match for an NSEntityDescription to a managed object subclass
I've fixed the Error
The Following is Required
var body: some Scene {
WindowGroup {
let context = CoreDataStack.viewContext
// let context = appDelegate.persistentContainer.viewContext
ContentView()
.environment(\.managedObjectContext, context)
}
It seems that the loading of the Context from the Static Variable into the Environment does not fire in the expected sequence, so that when the class ContentView is in scope, the Object is not in the Environment in time to be utilised.
Instead, by assigning the Context prior to setting in the Environment, fixes the issue.
Ok... The issue was I had the following as my config, and hadn't replaced the products.library with products.executable
Incorrect Config
import PackageDescription
let package = Package(
name: "MyServer",
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(
name: "MyServer",
targets: ["MyServer"]),
],
dependencies: [
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
.package(url: "https://github.com/vapor/vapor.git", from: "4.0.0"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages this package depends on.
.target(
name: "MyServer",
dependencies: [dependencies: [
.product(name: "Vapor", package: "vapor")
]),]),
.testTarget(
name: "MyServerTests",
dependencies: ["MyLibrary1"]),
]
)
The Correct Config is shown here but is the same as that in the WWDC Session
import PackageDescription
let package = Package(
name: "MyServer",
platforms: [.macOS("12.0")],
products: [
.executable(
name: "MyServer",
targets: ["MyServer"]),
],
dependencies: [
.package(url: "https://github.com/vapor/vapor.git", .upToNextMajor(from: "4.0.0")),
],
targets: [
.executableTarget(
name: "MyServer",
dependencies: [
.product(name: "Vapor", package: "vapor")
]),
.testTarget(
name: "MyServerTests",
dependencies: ["MyServer"]),
]
)
Resolved Issue