I have a Core Data object, Account
, represented as a subclass of NSManagedObject
:
@interface Account : NSManagedObject
My entire app has been developing just fine, however, when I add the MessageUI.framework
so I can get a compose email view controller, all hell breaks loose. The app links and compiles fine, and runs just fine. Until, that is, I start interfacing with my previously working Account
objects. Then, I start getting these:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException',
reason: '"Account" is not a subclass of NSManagedObject.'
*** First throw call stack:
(0x202b012 ... 0x2385)
libc++abi.dylib: terminate called throwing an exception
This particular one of which was caused by:
// we need to insert a new account
Account *newAccount = [NSEntityDescription
insertNewObjectForEntityForName:[Account entityName]
inManagedObjectContext:self.managedObjectContext];
Now, I'm guessing that there is some class in the MessageUI.framework
causing the conflict, but I have a few questions:
MFMailComposeViewController
), so should the theoretical account not be MFAccount
?#import <MessageUI/MessageUI.h>
or the slightly tighter #import <MessageUI/MFMailComposeViewController.h>
, the latter of which I inspected and saw no definition of Account
, so I'm not sure why the possible conflicts would even be loaded.However, the Core Data framework is not restricted to database-style applications, nor is there an expectation of client-server behavior. The framework is equally as useful as the basis of a vector graphics application such as Sketch or a presentation application such as Keynote.
Core Data is a framework that you use to manage the model layer objects in your application. It provides generalized and automated solutions to common tasks associated with object life cycle and object graph management, including persistence. Core Data typically decreases by 50 to 70 percent the amount of code you write to support the model layer.
Through Core Data’s Data Model editor, you define your data’s types and relationships, and generate respective class definitions. Core Data can then manage object instances at runtime to provide the following features.
Overview 1 Persistence. Core Data abstracts the details of mapping your objects to a store, making it easy to save data from Swift and Objective-C without administering a database directly. 2 Undo and Redo of Individual or Batched Changes. ... 3 Background Data Tasks. ... 4 View Synchronization. ... 5 Versioning and Migration. ...
I've had this happen to me, with this is exact framework (the class was called Broadcaster
). In this case, the private Message
framework is linked by MessageUI
, and this framework provides the Account
implementation.
You can verify that the MessageUI framework loads an Account
class by making a new project, and in the app delegate's application:didFinishLaunchingWithOptions:
method, add the following code:
NSString *account = @"Account";
Class accountClass = NSClassFromString(account);
NSLog(@"accountClass = %@",accountClass);
On a fresh project this will print accountClass = (null)
but after adding MessageUI it will print accountClass = Account
.
Furthermore, if you use class-dump
on the private Message
framework, you'll see the interface declaration for Account
.
Now, you list 5 items in your post as questions, I'll try to address them
Message
framework is weakly linked and thus won't cause a duplicate symbol error at link time.Message
framework.#import
, but at
run time, all the classes are loaded with your application and there
is no "visibility" or anything like that enforced in the runtime.As far as a course of action, I just renamed my model class to have a prefix. I'm not aware of any other solution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With