i have a core data database that start from the AppDelegate, and there i’ll do this:
MasterViewController *masterViewController = [[[MasterViewController alloc] initWithNibName:@"MasterViewController" bundle:nil] autorelease];
masterViewController.managedObjectContext = self.managedObjectContext;
so in this way i can access to the database in the master view, then i want access to the core data in other classes, and i do this:
id delegateContext = [[UIApplication sharedApplication] delegate];
NSManagedObjectContext *context = [delegateContext managedObjectContext];
but when i add, and access the information, i have some bad Exc access and other error in various part of the code when i try to access to the information of the database, so i think that maybe i have used in bad way the core data, to access the information from other classes.
maybe i have to release the delegatecontext?…i haven’t release it in any class i have used it, and if i have release it, where i have do it?
anyone can help me?
Problem is you are taking delegateContext of type
idinstead ofNSManagedObjectContextand assigning it to*contextin these two lines.How about adding these lines whenever you need to save or access
managedObjectContext, check it if itsnilifYEScopy it fromAppdelegate.Just try to remove your these two lines and add the above if condition I am suggesting. Should work.
after
@implementationcreate instance ofAppdelegatein
viewDidLoadmethod…