I am trying to pass a context from my app delegate to my rootview, then to my secondary view. The secondary view is where all the data is really loaded, the rootview is just a quick synopsis of a few key points. When I instantiate the context in appDelegate i log to check if it is not nil:
NSManagedObjectContext *context = [self managedObjectContext];
if (!context) {
//Handle error
}
if (context == nil) {
NSLog(@"Context is nil in appdelegate");
}
else {
NSLog(@"Context is set in appdelegate");
}
then set the rootViewController's context as
rootViewController.context = context;
followed by the same check, both show not nil. Then I push the view. Then I check to see if context is set during viewDidLoad and it is nil. The rootViewController:
#import <UIKit/UIKit.h>
@interface RootViewController : UITableViewController <NSFetchedResultsControllerDelegate> {
NSFetchedResultsController *fetchedResultsController;
NSManagedObjectContext *context;
NSMutableArray *rootViewContentArray;
}
@property (nonatomic, retain) NSFetchedResultsController *fetchedResultsController;
@property (nonatomic, retain) NSManagedObjectContext *context;
@end
#import "RootViewController.h"
#import "DetailViewController.h"
#import "SwapViewController.h"
#import "Swap.h"
@implementation RootViewController
@synthesize fetchedResultsController, context;
#pragma mark -
#pragma mark View lifecycle
- (void)viewDidLoad {
[super viewDidLoad];
//initialize array for rootView
rootViewContentArray = [[NSMutableArray alloc] init];
NSArray .....set array values....
//check context
if (context == nil){
NSLog(@"RootViewcontroller context is nil during viewdidload");
}
if (!(context == nil)){
NSLog(@"RootViewcontroller context is set during viewdidload");
}
//fill array
.........
}
Am I missing something small, or do I have a fundamental misunderstanding here? Also, it seems to me that if I set a variable on a view I create it should still be instantiated when the view loads. I am going through the example apps and using the books by Apress on iPhone developing and I try to create simple apps with what I have learned so far. The Core Data apps seem either way too simple or way above my head and I'm trying to make the jump. Any help would be greatly appreciated! Thanks.