title: SIGABRT with core data object context from AppDelegate in base controller
body: <p>I realise that best practice is to pass an object context down from the first controller in an app but given that my app starts with a navigation controller and has some view controllers which are content only and do not require core data I thought this would be a simpler solution.</p>
  
  <p>Header:</p>
  
  <pre><code>#import &lt;UIKit/UIKit.h&gt;
  #import "AppDelegate.h"
  
  @interface CoreDataViewController : UIViewController
  - (void)saveContext;
  
  //See ggfela's answer
  //@property (readonly, strong, nonatomic) AppDelegate *appDelegate;
  //@property (readonly, strong, nonatomic) NSManagedObjectContext *managedObjectContext;
  
  @property (readonly, weak, nonatomic) AppDelegate *appDelegate;
  @property (readonly, weak, nonatomic) NSManagedObjectContext *managedObjectContext;
  
  @end
  </code></pre>
  
  <p>Implementation:</p>
  
  <pre><code>#import "CoreDataViewController.h"
  
  @implementation CoreDataViewController
  
  @synthesize appDelegate = _appDelegate;
  @synthesize managedObjectContext = _managedObjectContext;
  
  -(AppDelegate *)appDelegate
  {
      if(!_appDelegate) {
          _appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
      }
  
      return _appDelegate;
  }
  
  -(NSManagedObjectContext *)managedObjectContext
  {
      if(!_managedObjectContext) {
          _managedObjectContext = self.appDelegate.managedObjectContext;
      }
  
      return _managedObjectContext;
  }
  
  - (void)saveContext
  {
      [self.appDelegate saveContext];
  }
  
  @end
  </code></pre>
  
  <p>When I inherit from this class then try to access the managed object context I'm getting a SIGABRT error which I gather means there is probably a memory leak somewhere. I'm pretty new to Objective-C so don't know too much about debugging it.</p>
  
  <p>Can anyone tell me what I'm doing wrong.</p>
  
  <p>Also should I really be doing it the other way (i.e. passing context from controller to child controller) and might apple block my app as a result?</p>