1

I have an application, that uses Core Data. I have two devices A and B. I need to provide a possibility to copy my database from device A to device B (device B can use these database if it wish).

1) Right now I created an application with Core Data at the very beginning. And Xcode automatically inserted app.xcdatamodeld file to my application bundle and added code to AppDelegate file to connect it

The question: how can I use app.xcdatamodeld from Documents folder? (if I copied file from other device, the file will be in Documents folder.) What settings and code should I change to make this possible?

2) What is the best way to transfer app.xcdatamodeld file from Documents folder of A device to the Documents folder of B device.

Florian Pilz
  • 8,002
  • 4
  • 22
  • 30
Paul T.
  • 4,938
  • 7
  • 45
  • 93
  • Check my answer at this question: http://stackoverflow.com/a/9757198/108574 . You need to transfer 2 files, .xcdatamodel and .sqlite . – He Shiming Apr 12 '12 at 11:18

1 Answers1

1

You can use a model file from anywhere, just set it up when you set up the NSManagedObjectModel:

// Create a path pointing at your model in the Documents folder
NSURL *modelURL = [NSURL fileURLWithPath:modelPath];
NSManagedObjectModel *managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];    

You could use iCloud to transfer your .xcdatamodeld (which is actually a folder) or your .xcdatamodel.

nevan king
  • 112,709
  • 45
  • 203
  • 241