‘Cannot find type ‘persistenceController’ in scope’

I’m trying to run this app, but the build fails with the error ‘Cannot find type ‘persistenceController’ in scope’.

I’ve tried cleaning the build file and quitting Xcode. The only thing I’ve done is add a new .env file to the root with my API key per the instructions.

https://github.com/jackderemiah/betterlox

import Foundation
import CoreData

@main
struct MovieSandboxApp: App {
    let persistenceController = PersistenceController.shared
    var body: some Scene {
        WindowGroup {
            ContentView()
                .environment(\.managedObjectContext, persistenceController.container.viewContext)
        }
    }
}

  • Where do you have an actor named PersistenceController in your project file?

    – 

  • And what is ‘import CoreData’ for?

    – 

  • Ok, it took me some time to get it but this isn’t your own code right? You have downloaded the linked project and tried to build it but it fails. I haven’t downloaded it but when quickly browsing the content I cannot find any PersistenceController type in the project so it won’t build. I suggest you contact the owner of the project instead to fix the issue or add that class yourself (it’s most likely the default one you get when creating a new project in Xcode that uses Core Data).

    – 

  • Correct it is not my code. And niether PersistenceController or persistenceController exist anywhere else in the project like you said. Thanks for the advice, I will set up the default class and see if that works!

    – 

Leave a Comment