Please or Register to create posts and topics.

Swift can't find the Entity Core Data

I'm following a book and I'm trying to add a Core Data to my project. You have the full source code on GitHub.

In Xcode a pass a new Entity for Core Data called ToDoCR, very basic.

ToDoCR in Xcode


When I try to use the ToDoCR entity, I get some errors from Xcode.

Cannot find type 'ToDoCD' in scope

var todoCDs: [ToDoCD] = []

override func viewDidLoad() {

func getToDos() {
    if let context = (UIApplication.shared.delegate as? 
       AppDelegate)?.persistentContainer.viewContext {
        if let toDosFromCoreData = try? context.fetch(ToDoCD.fetchRequest()) {
            if let toDos = toDosFromCoreData as? [ToDoCD] {
                todoCDs = toDos


Do I have to import a library to access the Core Data? What did I miss in this code?

For same reasons, this seems a common problem with XCode. To fix the issue, just close and reopen XCode and then open your project. The project will be ok.