Note that there are some explanatory texts on larger screens.

plurals
  1. POError: nil is not a legal NSManagedObjectContext
    primarykey
    data
    text
    <p>I have checked some other threads but can't find an answer.</p> <p>I am following a tutorial on Core Data and I am trying to apply it to my utility app.</p> <p>The following code is in the application delegate: </p> <pre><code>- (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:&amp;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:&amp;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; } </code></pre> <p>My flipside view controller has the following code</p> <pre><code>- (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:&amp;error]; } </code></pre> <p>I am getting the following error:</p> <pre><code>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) </code></pre> <p>It is something to do with the flipside view controller.m file where the managed object context is coming up as nil. I do not understand why this is. Any help would be greatly appreciated.</p> <p>Cheers.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload