3

어떻게하면 NSInternalInconsistencyException을 해결할 수 있습니까? ', reason :'+ entityForName : 실패한 보고서

내 코드는 다음과 같습니다.

NSManagedObjectContext *context = [self.fetchedResultsController managedObjectContext]; 
     NSEntityDescription *entity = [[self.fetchedResultsController fetchRequest] entity]; 
     NSManagedObject *newManagedObject = [NSEntityDescription insertNewObjectForEntityForName:[entity name] inManagedObjectContext:context]; 

     // If appropriate, configure the new managed object. 
     [newManagedObject setValue:[NSDate date] forKey:@"date"]; 

      // Save the context. 
      NSError *error = nil; 
      if (![context save:&error]) { 
       NSLog(@"Unresolved error %@, %@", error, [error userInfo]); 
       abort(); 
     } 
.h .h .h 헤더 파일에 있습니다.

@interface TretiViewController : UIViewController <NSFetchedResultsControllerDelegate> { 

NSFetchedResultsController *fetchedResultsController_; 
    NSManagedObjectContext *managedObjectContext_; 

// private NSString *accountID; 
} 


@property (nonatomic, retain) NSManagedObjectContext *managedObjectContext; 
@property (nonatomic, retain) NSFetchedResultsController *fetchedResultsController; 

코어 데이터를 사용하여 데이터를 저장해야하지만 오류가 발생합니다.

NavTest[1372:207] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '+entityForName: could not locate an NSManagedObjectModel for entity name 'Obrat'' 
*** Call stack at first throw: 
(
0 CoreFoundation      0x00f92be9 __exceptionPreprocess + 185 
1 libobjc.A.dylib      0x010e75c2 objc_exception_throw + 47 
2 CoreData       0x00cbf45b +[NSEntityDescription entityForName:inManagedObjectContext:] + 187 
3 NavTest        0x0000c210 -[TretiViewController fetchedResultsController] + 187 
4 NavTest        0x00007a76 -[TretiViewController ukazObrat0] + 38 
5 UIKit        0x002c4a6e -[UIApplication sendAction:to:from:forEvent:] + 119 
6 UIKit        0x003531b5 -[UIControl sendAction:to:forEvent:] + 67 
7 UIKit        0x00355647 -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527 
8 UIKit        0x00354438 -[UIControl touchesBegan:withEvent:] + 277 
9 UIKit        0x0054f987 _UIGestureRecognizerSortAndSendDelayedTouches + 3609 
10 UIKit        0x005500fc _UIGestureRecognizerUpdateObserver + 927 
11 CoreFoundation      0x00f73fbb __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 27 
12 CoreFoundation      0x00f090e7 __CFRunLoopDoObservers + 295 
13 CoreFoundation      0x00ed1bd7 __CFRunLoopRun + 1575 
14 CoreFoundation      0x00ed1240 CFRunLoopRunSpecific + 208 
15 CoreFoundation      0x00ed1161 CFRunLoopRunInMode + 97 
16 GraphicsServices     0x018c7268 GSEventRunModal + 217 
17 GraphicsServices     0x018c732d GSEventRun + 115 
18 UIKit        0x002d342e UIApplicationMain + 1160 
19 NavTest        0x00002594 main + 102 
20 NavTest        0x00002525 start + 53 
) 

in NavTest.xcdatamodel 나는 두 개의 entytis Obrta whith attributesEvet를 가지고있다.

- (NSFetchedResultsController *)fetchedResultsController { 

    if (fetchedResultsController_ != nil) { 
     return fetchedResultsController_; 
    } 


    // Set up the fetched results controller. 

    // Create the fetch request for the entity. 
    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; 
    // Edit the entity name as appropriate. 
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"Obrat" inManagedObjectContext:self.managedObjectContext]; 
    [fetchRequest setEntity:entity]; 

    // Set the batch size to a suitable number. 
    [fetchRequest setFetchBatchSize:20]; 

    // Edit the sort key as appropriate. 
    NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"date" ascending:NO]; 
    NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil]; 

    [fetchRequest setSortDescriptors:sortDescriptors]; 

    // Edit the section name key path and cache name if appropriate. 
    // nil for section name key path means "no sections". 
    NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:nil cacheName:@"Root"]; 
    aFetchedResultsController.delegate = self; 
    self.fetchedResultsController = aFetchedResultsController; 

    [aFetchedResultsController release]; 
    [fetchRequest release]; 
    [sortDescriptor release]; 
    [sortDescriptors release]; 

    NSError *error = nil; 
    if (![fetchedResultsController_ performFetch:&error]) { 

// Replace this implementation with code to handle the error appropriately. 

// abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. If it is not possible to recover from the error, display an alert panel that instructs the user to quit the application by pressing the Home button. 

    NSLog(@"Unresolved error %@, %@", error, [error userInfo]); 
    abort(); 
    } 

    return fetchedResultsController_; 
    }  

무엇이 누락 되었습니까?

+0

코드에서 NSEntityDescription와 같은 유지해야 엑스 코드로 만들

NSEntityDescription *entity = [NSEntityDescription entityForName:@"Obrta" inManagedObjectContext:self.managedObjectContext]; 

Entity named

에 있지만하지 않습니다 나를 도왔다 http://stackoverflow.com/questions/657042/iphone-core-data-example-produces-exception – Csabi

답변

0

변경 fetchedResultsController의 코드 :

NSEntityDescription *entity = [NSEntityDescription entityForName:@"Obrat" inManagedObjectContext:self.managedObjectContext]; 

당신은 내가 어떤 스레드를 발견

0

"Obrta"이라는 엔티티가 있지만이 코드는 "Obrat" 유형의 객체를 생성한다고합니다. 그 오타를 수정하면 문제가 해결됩니다.

관련 문제