他のスレッドをいくつか確認しましたが、答えが見つかりません。
Core Data のチュートリアルに従っており、それをユーティリティ アプリに適用しようとしています。
次のコードは、アプリケーション デリゲートにあります。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:
(NSDictionary *)launchOptions
{
NSManagedObjectContext *context = [self managedObjectContext];
MessageDetails *messageDetails = [NSEntityDescription
insertNewObjectForEntityForName:@"MessageDetails"
inManagedObjectContext:context];
messageDetails.to = @"0861234567";
messageDetails.message = @"Test Message";
NSError *error;
if (![context save:&error]) {
NSLog(@"Whoops, couldn't save: %@", [error localizedDescription]);
}
//Lists out all the objects currently in the database:
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription
entityForName:@"MessageDetails" inManagedObjectContext:context];
[fetchRequest setEntity:entity];
NSArray *fetchedObjects = [context executeFetchRequest:fetchRequest error:&error];
for (MessageDetails *details in fetchedObjects) {
NSLog(@"To: %@", details.to);
NSLog(@"Message: %@", details.message);
}
// Override point for customization after application launch.
CCCMainViewController *controller = (CCCMainViewController *)self.window.rootViewController;
controller.managedObjectContext = self.managedObjectContext;
return YES;
}
私のフリップサイドView Controllerには次のコードがあります
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription
entityForName:@"MessageDetails" inManagedObjectContext:managedObjectContext];
[fetchRequest setEntity:entity];
NSError *error;
self.allMessageDetails = [managedObjectContext executeFetchRequest:fetchRequest error:&error];
}
次のエラーが表示されます。
2013-09-25 02:09:11.238 SendMessageV2[9267:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+entityForName: nil is not a legal NSManagedObjectContext parameter searching for entity name 'MessageDetails''
*** First throw call stack:
(0x301fdf53 0x3a5d46af 0x2ff5332b 0x25345 0x32973603 0x329733c1 0x32a1d637 0x32a59d7b 0x32a586b3 0x32a57705 0x32c3265b 0x329a3f3f 0x329a3edf 0x329a3eb9 0x3298fb3f 0x329a392f 0x329a3601 0x3299e68d 0x32973a25 0x32972221 0x301c918b 0x301c865b 0x301c6e4f 0x30131ce7 0x30131acb 0x34e52283 0x329d3a41 0x23cc9 0x3aadcab7)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
これは、管理対象オブジェクトのコンテキストが nil になっているフリップサイド ビュー controller.m ファイルと関係があります。これがなぜなのかわかりません。どんな助けでも大歓迎です。
乾杯。