数据核心NSException

时间:2014-09-10 11:48:34

标签: objective-c core-data ios7 nsexception

我不知道我的问题在哪里,因为实体" Utente"存在。

错误代码:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+entityForName: nil is not a legal NSManagedObjectContext parameter searching for entity name 'Utente''
*** First throw call stack:
(
    0   CoreFoundation                      0x0000000101bf0495 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x00000001016f099e objc_exception_throw + 43
    2   CoreData                            0x0000000101e76599 +[NSEntityDescription entityForName:inManagedObjectContext:] + 217
    3   CoreData                            0x0000000101eb2e7e +[NSEntityDescription insertNewObjectForEntityForName:inManagedObjectContext:] + 30
    4   VucmpraJson                         0x000000010000514b -[LoginViewController login:] + 4843
    5   UIKit                               0x000000010029ef06 -[UIApplication sendAction:to:from:forEvent:] + 80
    6   UIKit                               0x000000010029eeb4 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 17
    7   UIKit                               0x000000010037b880 -[UIControl _sendActionsForEvents:withEvent:] + 203
    8   UIKit                               0x000000010037adc0 -[UIControl touchesEnded:withEvent:] + 530
    9   UIKit                               0x00000001002d5d05 -[UIWindow _sendTouchesForEvent:] + 701
    10  UIKit                               0x00000001002d66e4 -[UIWindow sendEvent:] + 925
    11  UIKit                               0x00000001002ae29a -[UIApplication sendEvent:] + 211
    12  UIKit                               0x000000010029baed _UIApplicationHandleEventQueue + 9579
    13  CoreFoundation                      0x0000000101b7fd21 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    14  CoreFoundation                      0x0000000101b7f5f2 __CFRunLoopDoSources0 + 242
    15  CoreFoundation                      0x0000000101b9b46f __CFRunLoopRun + 767
    16  CoreFoundation                      0x0000000101b9ad83 CFRunLoopRunSpecific + 467
    17  GraphicsServices                    0x00000001040d0f04 GSEventRunModal + 161
    18  UIKit                               0x000000010029de33 UIApplicationMain + 1010
    19  VucmpraJson                         0x0000000100021d13 main + 115
    20  libdyld.dylib                       0x00000001025f15fd start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

代码:

@property (nonatomic,strong) NSManagedObjectContext* managedObjectContext;

。 。

    NSManagedObjectContext *context = [self managedObjectContext];
NSManagedObject * Utente = [NSEntityDescription          insertNewObjectForEntityForName:@"Utente" inManagedObjectContext:context];
[Utente setValue: emailText.text forKey:@"email"];
NSError *error;
    //[context save:&error];
  if (![context save:&error]) {
    NSLog(@"Whoops, couldn't save: %@", [error localizedDescription]);
}

实体:Utente

属性:电子邮件;密码

对很多人来说很重要

1 个答案:

答案 0 :(得分:1)

  

nil不是合法的NSManagedObjectContext参数,用于搜索实体名称“Utente”

表示您的托管对象上下文为零。检查self.managedObjectContext作业。

修改

if (! [self managedObjectContext]) {
    NSLog(@"You will receive your exception");
} else {
    // Insert new entity into specified context
}
相关问题