Xcode 11 doesn't recognize Core data Entity
Please try this solutions !!
Solution 1 :-
Product->Build for testing solved this issue for me(it solves most unresolved identifier bugs for some strange reason)
Solution 2 :-
changing import Foundation to import UIKit.
It seems like UIApplication isn't included in Foundation framework.
Solution 3 :- Highlight the Data Model, go to Editor -> Create NSManagedObject Subclass...
Solution 4 :-
Create the NSManagedObject files and then delete them and everything is fixed.
Hope this helps thank you.
Xcode 11.4.1 Core Data model not recognised
Xcode 11.4
I created a new project and created your xcdatamodel
as you have and Codegen set to Class Definition. The only exception being the Module field in the Data Model Inspector is cleared and set to Global namespace.
After building the project, the RefuelSheet
class was not recognised by the compiler. Likewise following a Clean + Build. However, I closed Xcode and upon reopening and building, the class was recognised.
If that doesn't work, try creating the class manually as well:
Select your xcdatamodel > Editor > Create NSManagedObject Subclass
Build the project and it should tell you the classes are created twice. Now, delete the manually generated classes and Clean + Build again.
Personally, I always use manual codegen for CoreData
classes because it gives more fine-grained control with Types (particularly with relationships), and custom functions.
As an aside, when you create an instance of a CoreData
class, you need to use one of the designated initialisers, typically (context:)
:
let appDelegate = UIApplication.shared.delegate as! AppDelegate
let moc = appDelegate.persistentContainer.viewContext
let newSheet = RefuelSheet(context: moc)
Core Data Model doesn't appear to be reflected in app
I finally figured it out:
In Xcode 7 you would have to enter the class name and, in Swift, set the module to "Current Project Module". I assumed that wouldn't be necessary anymore in Xcode 8, since it automatically generates the source files. You do have to manually set the class name to the name of the generated class though, to make Xcode generate the @objc(ClassName)
(i have no idea why it needs that annotation - manually created classes for CoreData entities work without it for me). Also you have to NOT manually set the module, because otherwise Xcode can't find the generated class anymore.
Core Data entities missing when tested on device
This is expected behavior, because youк needed data stored in simulator memory on the mac, and you should copy that database file from simulator to Supporting Files in main bundle of your app and then copy to Documents directory of your app in real device.
So steps:
- find simulator file:
Sqlite File Location Core Data - copy this file to Supporting file of your project
- copy that file to Documents directory: iOS ship application with pre populated sqlite database
Core Data Entity Name Not Found
Since it looks like this is running just as the application launches, I am guessing you have not set up your managed object model and your persistent store coordinator before you created the NSManagedObjectContext...
So try something like:
NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"myModel" withExtension:@"momd"];
NSManagedObjectModel* managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];
NSURL *documentsDirectory = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
NSURL *dbURL = [documentsDirectory URLByAppendingPathComponent:@"myModel.sqlite"];
NSPersistentStoreCoordinator *persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:managedObjectModel];
if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:dbURL options:nil error:&error]) {
// handle error
}
NSManagedObject *managedObjectContext = [[NSManagedObjectContext alloc] init];
[managedObjectContext setPersistentStoreCoordinator:coordinator];
Blabla *t = [NSEntityDescription insertNewObjectForEntityForName:@"Status" inManagedObjectContext:managedObjectContext];
...
(release everything when you are done)
Of course, in a real application, you will probably want to keep these around as properties or instance variables in the application delegate and release them in the dealloc
method.
Xcode error saying cannot find type 'TestModelCoreData' in scope when using core data fetch request, yet it compiles and runs
I just reopened Xcode .
SwiftUI 2.0 CoreData issues with new project - 'Cannot find type 'Item' in scope'
Related Topics
Healthkit Error: Missing Com.Apple.Developer.Healthkit Entitlement
Swiftui - Using Geometryreader Without Modifying the View Size
How to Get the Download Progress with the New Try Await Urlsession.Shared.Download(...)
Get a Unique String for a Given Anyobject
How to Handle Touch Gestures in Swiftui in Swift Uikit Map Component
Swift: Deallocate Gamescene After Transition to New Scene
An Nsmanagedobject of Class 'Classname' Must Have a Valid Nsentitydescription.' Error
Initialization of 'Unsafemutablerawpointer' Results in a Dangling Pointer
Uisearchcontroller in Navigationitem iOS 11 Apple Way
How to Use Swift Flatmap to Filter Out Optionals from an Array
Collection View Cell Button Not Triggering Action
How to Rounded the Corners When I Draw Rectangle Using Uibezierpath Points
Get Resource Url from Project Specific Path
How to Initialise Cvpixelbufferref in Swift
Swift: How to Open File with Associated Application
What Is a Good Alternative for Static Stored Properties of Generic Types in Swift