Error When Project is Built

I’m building a project that uses SwiftUi, CoreData and CloudKit and I automatically get the error “cannot find the item in scope” located in my content view twice. Why does that happen when I select CloudKit before building the project? If I don’t select I don’t have any errors at all.

Share your code so that we know what you are talking about.

struct ContentView: View {

@Environment(.managedObjectContext) private var viewContext

@FetchRequest(

sortDescriptors: [NSSortDescriptor(keyPath: \Item.timestamp, ascending: true )],

animation: .default)

private var items: FetchedResults //error: can not find item in scope

I also have it in another method.

private func addItem() {
withAnimation {
let newItem = Item(context: viewContext)
newItem.timestamp = Date() // error: can not find item in scope

        do {
            try viewContext.save()
        } catch {
            // Replace this implementation with code to handle the error appropriately.
            // fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
            let nsError = error as NSError
            fatalError("Unresolved error \(nsError), \(nsError.userInfo)")
        }
    }
}