I created the database through UIManagedDocument. If I slowly add entries, everything works. If I quickly (3-4 seconds between records), the records fail when they are removed and may not be saved when the application is stopped / started.
A UIManagedDocument is created in viewDidAppear and modified into "useDocument" (code below), which checks for a non-existent database and creates it if necessary or simply opens it.
Again, I think my problem is that the main data is not immediately stored in SQLite.
-(void)setExampleDatabase:(UIManagedDocument *)exampleDatabase { if ( _exampleDatabase != exampleDatabase ) { _exampleDatabase = exampleDatabase; NSMutableDictionary *pragmaOptions = [NSMutableDictionary dictionary]; [pragmaOptions setObject:@"FULL" forKey:@"synchronous"]; [pragmaOptions setObject:@"1" forKey:@"fullfsync"]; NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys: pragmaOptions, NSSQLitePragmasOption, [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption, [NSNumber numberWithBool:YES, NSInferMappingModelAutomaticallyOption, nil]; exampleDatabase.persistentStoreOptions = options;
source share