Forum

PureSourceCode.com Forum
Swift can't find th...
 
Share:
Notifications
Clear all

Swift can't find the Entity Core Data

2 Posts
1 Users
0 Likes
1,177 Views
(@enrico)
Member Admin
Joined: 4 years ago
Posts: 151
Topic starter  

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() {
    super.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
                tableView.reloadData()
            }
        }
    }
}

 

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


   
Quote
(@enrico)
Member Admin
Joined: 4 years ago
Posts: 151
Topic starter  

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. 


   
ReplyQuote
Share: