Xcode 11 Doesn't Recognize Core Data Entity

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.

Sample Image

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:

  1. find simulator file:
    Sqlite File Location Core Data
  2. copy this file to Supporting file of your project
  3. 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



Leave a reply



Submit