0

I made a Core Data application, and I want to save the file.sqlite to a different directory from the default. I came across this SO thread, then posted this SO question, and the project appears to be compling, but my the file.sqlite is not getting saved in the location I specified. I created a method, and added some code to the AppDelegate.m file, but the storeURL variable is still saving the file.sqlite in the default "Documents directory. How do I call the method I created within the AppDelegate.m file to specify the proper location for the storeURL variable?

Should I just change,

NSURL *storeURL = [NSURL fileURLWithPath: [docPath stringByAppendingPathComponent:@"Accounts.sqlite"]];

to

NSURL *storeURL = [NSURL fileURLWithPath: [documentsDirectoryPath stringByAppendingPathComponent:@"Accounts.sqlite"]];

Also will this break iOS Simulator support?

Community
  • 1
  • 1
ipatch
  • 3,933
  • 8
  • 60
  • 99
  • 1
    I am sorry if this sounds rude, but I think everything has been said in the comments to your previous question [http://stackoverflow.com/questions/11812576/ios-how-to-change-documents-directory]. If you don't know how to call your own method `documentsDirectoryPath` and if you do not use the debugger to find out why your `storeURL` is wrong, than we cannot help you. – Martin R Aug 07 '12 at 10:48

1 Answers1

1

I solved this problem by keeping the default documents path for the simulator, and then setting up a different documents path for the device. The following code is in my AppDelegate.m file

// add conditional code for simulator and iDevice
#if TARGET_IPHONE_SIMULATOR
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

NSString *docPath = [documentPaths objectAtIndex:0];

NSURL *storeURL = [NSURL fileURLWithPath: [docPath stringByAppendingPathComponent:@"Accounts.sqlite"]];
#else
// jailbroken path - /var/mobile/Library/KegCop/
NSString *docPath = self.documentsDirectoryPath;

NSURL *storeURL = [NSURL fileURLWithPath: [docPath stringByAppendingPathComponent:@"Accounts.sqlite"]];
#endif
ipatch
  • 3,933
  • 8
  • 60
  • 99