Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CoreData: warning: Unable to load class named 'WEEReadings' for entity 'Readings'. Class not found, using default NSManagedObject instead

OK, it's time for the community help after hours and hours of searching.

I have a static library and using this awesome script I generate my static framework which includes the universal static library, also I create a bundle including the ReadingsCoreDataModel.momd which includes the ReadingsCoreDataModel.mom. All good, I provide these to my client iOS application, all builds correctly and starting the app kinked to my framework and using the bundle, I have a singleton WEEDataStore class in my static library used by another class named Worker, checked, NSManagedObjectModel is not nil and looks to be loaded correctly, NSPersistentStoreCoordinator is not nil, NSManagedObjectContext is not nil.

In the WEEDataStore I have a save method which I call from the Worker class in my static library.

In my ReadingsCoreDataModel.momd I have created an Entity with Name Readings and class WEEReadings.

I do the following in the Worker class

WEEReadings* readingsEntity = [NSEntityDescription insertNewObjectForEntityForName:@"Readings" inManagedObjectContext:[[WEEDataStore sharedInstance] managedContext]];
[readingsEntity appendWithReadingsModel:self.readingsModel];
[[WEEDataStore sharedInstance] save];

The result is to get the following error

CoreData: warning: Unable to load class named 'WEEReadings' for entity 'Readings'.  Class not found, using default NSManagedObject instead.
2014-12-13 20:11:30.080 TestClient[6854:2487108] -[NSManagedObject appendWithReadingsModel:]: unrecognized selector sent to instance 0x1700ccda0
2014-12-13 20:11:30.084 TestClient[6854:2487108] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSManagedObject appendWithReadingsModel:]: unrecognized selector sent to instance 0x1700ccda0'

I have almost read all the similar errors, most troubleshooting with Swift, or typo errors with the model, other suggesting to have the same model name as the application name, I don't think I can do this or it is related to the error.

All my headers inside my static library are Project except the ones exposed to the client that are added as Public. Also tried to add them all as public but it didn't make any difference.

All Core Data operations are internal.

It seems like the Core Data model is loaded properly but cannot find my class which is definitely included in the static library that is included in the framework.

Any ideas before I register to the mad house?

like image 256
George Taskos Avatar asked Dec 14 '14 01:12

George Taskos


2 Answers

Add -ObjC linker flag to your project to force linker to load all classes from your library.

like image 197
Rob Zombie Avatar answered Nov 13 '22 07:11

Rob Zombie


I had a similar problem recently. -ObjC linker flag, as mentioned in a different answer to this question, didn't help. Turns out my NSManagedObject subclasses had @objc attributes on them, so if you have

@objc(Model)
final class Model: NSManagedObject {
  // ...
}

changing it to this might fix the problem :

final class Model: NSManagedObject {
  // ...
}
like image 39
Max Desiatov Avatar answered Nov 13 '22 08:11

Max Desiatov