Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Honestly, I think you've done quite a number on this code... ;)</p> <p>OK, first off, in your save method, don't create another NSManagedObjectContext, use the instance variable you already declared, "managedObjectContext."</p> <p>Secondly, I think you've made things way too complicated for yourself... Storing Core Data is actually shockingly simple once you've created the NSManagedObject subclasses and set up everything in the App Delegate...</p> <p>It seems as if you wouldn't need any info from the "fetchedResultsController" at that point in your code, since you're saving, not fetching. Maybe try changing your save method to something like:</p> <pre><code>- (IBAction)save:(id)sender { NSEntityDescription *entity = [NSEntityDescription insertNewObjectForEntityForName:@"MessageDetails" inManagedObjectContext:self.managedObjectContext]; // If appropriate, configure the new managed object. [entity setValue:self.toTextField.text forKey:@"to"]; [entity setValue:self.messageTextField.text forKey:@"message"]; // Save the context. NSError *error = nil; [self.managedObjectContext save:&amp;error] if (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(); } </code></pre> <p>}</p> <hr> <p>Edit: And to get the managed object context from the app delegate...</p> <p>Right after your @synthesize's, create a variable for the App Delegate.</p> <pre><code>AppDelegate* appDelegateController; </code></pre> <p>And in viewDidLoad, initialize it:</p> <pre><code>appDelegateController = (AppDelegate*)[[UIApplication sharedApplication] delegate]; </code></pre> <p>Right after viewDidLoad (or anywhere you want), you can stick in a method to declare the managed object context:</p> <pre><code>- (NSManagedObjectContext*)managedObjectContext { return appDelegateController.managedObjectContext; } </code></pre> <p>Then back in viewDidLoad, call that method with:</p> <pre><code>self.managedObjectContext = [self managedObjectContext]; </code></pre>
    singulars
    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.
    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