I have a plain XCode CoreData enabled iPhone/iPad navigation application. In this I have modifed the data it initially defines to represent some categories in the table view with associated images. For example by modifying a Event to Category elsewhere, changing the .xcdatamodel file and altering this call in RootController.m:
- (void)configureCell:(DeliciousCategoryCell *)cell atIndexPath:(NSIndexPath *)indexPath {
NSManagedObject *managedObject = [self.fetchedResultsController objectAtIndexPath:indexPath];
cell.categoryLabel.text = [[managedObject valueForKey:@"name"] description];
NSString *filePath = [[NSBundle mainBundle] pathForResource:cell.categoryLabel.text ofType:@"tiff"];
cell.categoryImage.image = [[UIImage alloc] initWithContentsOfFile:filePath];
}
If I preload the data from an xml file by putting code in:
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
The data gets loaded in fine but the app subsequentially crashes with EXC_BAD_ACCESS. If I take that code out the app loads, my data is present and my categories display fine with the associated local images. I've tried moving the code in question elsewhere such as:
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator
and checking to make sure the data is empty however it still crashes yet loads the data. I can't seem to track down the cause of the EXC_BAD_ACCESS via the debugger as the stack trace is void of useful information. What I would like to know is an answer to the following as I cannot find it in apples documentation:
1) When such a Core Data based application first starts where should the calls to load in an initial data set go? I would ideally do this via the web but am currently just opening a local xml file for testing.
2) Once core data has been loaded I would like to enable the user to update the core data information by merging. Where should such code reside?
I don't have a problem with the logic just the location of the necessary code afaict. If anyone would like a listing of what I'm doing I'll provide but it is rather verbose. The code as implemented is taken straight from two apple tutorials. The latter detailing how to load in data without undue fetches/selects on the data base, however said tutorial doesn't say anything about where it should reside.