问题描述
在我的应用程序中,我使用核心数据
似乎有一个非常古怪的错误。
There seems to be a very weird bug in my app in which I'm using Core Data
.
我昨天关闭了这个项目,今天开始开发没有修改代码),现在每次我想添加一行到我的数据库,我得到一个异常说下面的类不是 NSManagedObject
,这是我可笑地确定不是真的,因为它是工作几天,第二,因为我自动生成为 NSManagedObject
子类。我尝试使用 Editor->在我的数据模型中创建NSManagedObject子类
重新生成类,但它根本没有帮助我。
I closed the project yesterday, and started development today ( with no modifications in code ) and now every time I wanna add a row to my database, I get an exception saying the following class is not a subclass of NSManagedObject
, which I'm ridiculously sure is not true, first because it was working for days, and second because I generated them automatically as NSManagedObject
subclasses. I tried regenerating classes using Editor->Create NSManagedObject Subclasses
in my data model, but it didn't help me at all.
这是很奇怪的,我得到这个异常的蓝色和所有的突然不在我的代码中的一行修改:(
It's really weird that I get this exception out of blue and all of a sudden WITHOUT EVEN A LINE OF MODIFICATION in my code :(
任何人有任何
感谢
Anybody got any idea ? I really appreciate any help.Thanks
BTW,这里有一些代码可能会有帮助:
BTW, Here're some code that may help :
错误:
由于未捕获异常而终止应用程序'NSInternalInconsistencyException',reason:'Message 不是NSManagedObject的子类。
消息类头文件(自动生成): >
Message Class Header File (Auto-Generated) :
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
@class File;
@interface Message : NSManagedObject
@property (nonatomic, retain) NSString * data;
@property (nonatomic, retain) NSDate * date;
@property (nonatomic, retain) NSString * fileId;
@property (nonatomic, retain) NSString * number;
@property (nonatomic, retain) NSString * status;
@property (nonatomic, retain) NSString * type;
@property (nonatomic, retain) NSString * xmppId;
@property (nonatomic, retain) File *contains;
@end
我尝试创建的方法一个新的邮件对象: sendXMPPMessage:(NSString *)messageStr containsFile:(NSData *)。
The method in which I try to create a new message object :
+ (void)sendXMPPMessage:(NSString *)messageStr containingFile:(NSData *)fileData toNumber:(NSString *)number
{
if(fileData == nil)
{
NSString *newID = [self generateNewXMPPMessageID];
SunBirdAppDelegate *appDelegate = (SunBirdAppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate sendXMPPMessage:messageStr withID:newID toNumber:number];
NSMutableDictionary *messageDataDic = [[NSMutableDictionary alloc] init];
[messageDataDic setObject:messageStr forKey:@"body"];
[messageDataDic setObject:@"Outgoing" forKey:@"type"];
[messageDataDic setObject:newID forKey:@"xmppId"];
[messageDataDic setObject:@"Sending" forKey:@"status"];
[messageDataDic setObject:[NSDate date] forKey:@"date"];
[messageDataDic setObject:number forKey:@"number"];
[Message messageWithMessageInfo:messageDataDic inManagedObjectContext:[appDelegate managedObjectContext]];
}
else
{
//Handle Database With File Data
}
}
创建新邮件对象 - >在邮件类别上创建类别(Message + Create.m):
+ (Message *)messageWithMessageInfo:(NSDictionary *)messageInfo inManagedObjectContext:(NSManagedObjectContext *)context
{
SunBirdAppDelegate *appDelegate = (SunBirdAppDelegate *)[[UIApplication sharedApplication] delegate];
Message *newMessage = nil;
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"Message"];
request.predicate = [NSPredicate predicateWithFormat:@"xmppId = %@", [messageInfo objectForKey:@"msgId"]];
NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"xmppId" ascending:YES];
request.sortDescriptors = [NSArray arrayWithObject:sortDescriptor];
NSError *error = nil;
NSArray *matches = [context executeFetchRequest:request error:&error];
if (!matches || ([matches count] > 1))
{
// handle error
}
else if ([matches count] == 0)
{
newMessage = [NSEntityDescription insertNewObjectForEntityForName:@"Message" inManagedObjectContext:context];
newMessage.data = [messageInfo objectForKey:@"body"];
newMessage.type = [messageInfo objectForKey:@"type"];
newMessage.date = [messageInfo objectForKey:@"date"];
newMessage.xmppId = [messageInfo objectForKey:@"xmppId"];
newMessage.status = [messageInfo objectForKey:@"status"];
newMessage.number = [messageInfo objectForKey:@"number"];
if ( [[messageInfo allKeys] containsObject:@"fileId"] )
{
newMessage.fileId = [messageInfo objectForKey:@"fileId"];
newMessage.contains = [messageInfo objectForKey:@"fileData"];
}
else
{
newMessage.fileId = NULL;
newMessage.contains = NULL;
}
}
else
{
newMessage = [matches lastObject];
NSLog(@"WARNING : NO NEW MESSAGE STORED IN DB ! MESSAGE WITH SAME XMPPID RETURNED");
}
[appDelegate saveContext];
return newMessage;
}
这是我被通知的行消息
不是 NSManagedObject
的子类:
And this is the line on which I'm being informed Message
is not a subclass of NSManagedObject
:
newMessage = [NSEntityDescription insertNewObjectForEntityForName:@MessageinManagedObjectContext:context];
推荐答案
消息
不能用于实体名...为什么? ... Apple ... ???
Message
cannot be used an an entity name ... why? ... Apple ... ???
不知道。
重命名为其他值,这通常可以解决问题。
Rename to something else and this usually solve the problem.
这篇关于奇怪的核心数据反应 - 未检测NSManagedObject子类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!