Amino acids Amino acids - 5 months ago 13
iOS Question

Where is the name/location of the core data file?

I'm just getting started learning CoreData for iOS and have written some exploratory code to store (via

ManagedObjectContext
save) and read data successfully.

However I've got lots of data in the file but want to start out again from scratch, so figured I'd just delete it manually in the file system.
But what's its name/location? I can't see anything that looks like it by manually browsing around, and while I've not finished reading my book on core data yet, flicking through it I can't find any reference to this sort of information.

TIA

Answer

The file is in the application directory of your iPhone simulator e.g. /Users/matthias/Library/Application Support/iPhone Simulator/5.0/Applications/EB33C087-A250-483E-96DD-D265ED3F0985/Documents/Foobar.sqlite

Just put a NSLog in the persistentStoreCoordinator getter to see the exact location.

Like this:

- (NSPersistentStoreCoordinator *)persistentStoreCoordinator {
    /* ... */    
    NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"Foobar.sqlite"];
    NSLog(@"CoreData Location: %@", storeURL);