0

I have an application based on the documents and I would like that when you create a new file the tableview are pre-populated with default data. I did the following:

  1. I launched my application and I populated the tables, then I saved the file Untitled.sqlite
  2. I imported the file Untitled.sqlite between the resources of my application
  3. I inserted the following code in the following file

MyApplicationDocumente.m:

- (id)init {
self = [super init];
if (self) {
    // Add your subclass-specific initialization here.
    NSFileManager *fileManager = [NSFileManager defaultManager];
    if (![fileManager fileExistsAtPath:@"/Users/andreabollini/Library/Developer/Xcode/DerivedData/Preventivi-euqsrtroavapbwfjvljrxamywbvf/Build/Products/Debug/Preventivi.app/Contents/Resources/en.lproj"]) {
        NSString *defaultStorePath = [[NSBundle mainBundle]
                                      pathForResource:@"Untitled" ofType:@"sqlite"];

        if (defaultStorePath) {
            [fileManager copyItemAtPath:defaultStorePath toPath:@"/Users/andreabollini/Library/Developer/Xcode/DerivedData/Preventivi-euqsrtroavapbwfjvljrxamywbvf/Build/Products/Debug/Preventivi.app/Contents/Resources/en.lproj" error:NULL];
            [tabella1 reloadData];
            [tabella2 reloadData];
        }
    }
}
return self;}

There are no errors, but it does not work. When I open the application, the tableview remains empty and nothing happens. What's wrong?

Jake Shaffer
  • 35
  • 1
  • 8
Andrea
  • 427
  • 3
  • 16
  • I did as you said, but nothing has changed. – Andrea Nov 10 '12 at 14:01
  • Is this an iOS or OS X app? And how are the table views populated? – Martin R Nov 10 '12 at 16:10
  • It is an application for OS X. There are two entity with tow tableview with a to-many relationship. – Andrea Nov 10 '12 at 16:23
  • @Andrea: Shouldn't you somehow open the data base after copying the file? – Martin R Nov 10 '12 at 16:27
  • @Andrea: Another point: You copy "Untitled.sqlite" to some folder where the application is *compiled*. This will not work if you move the app to a different folder. – Martin R Nov 10 '12 at 16:34
  • What do you mean? Please note that I have very little knowledge of Objective-C. For the second point, you're right, but I not know how to remedy the problem. – Andrea Nov 10 '12 at 16:35
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/19375/discussion-between-martin-r-and-andrea) – Martin R Nov 10 '12 at 16:36
  • It turned out that I am not the right person to help here. An expert in "Document based applications" is needed. – Martin R Nov 10 '12 at 17:30

0 Answers0