Основные данные отключить journal_mode не работают - PullRequest
0 голосов
/ 19 января 2019

Я хочу отключить режим ведения журнала в своем приложении основных данных.Это код:

- (NSPersistentContainer *)persistentContainer {
// The persistent container for the application. This implementation creates and returns a container, having loaded the store for the application to it.
@synchronized (self) {
    if (_persistentContainer == nil) {
        _persistentContainer = [[NSPersistentContainer alloc] initWithName:@"My_App"];

        NSURL *url = [[self applicationFilesDirectory] URLByAppendingPathComponent:@"My_App.sqlite"];
        NSPersistentStoreDescription *description=[[NSPersistentStoreDescription alloc]initWithURL:url];
        NSMutableDictionary *pragmaOptions=[NSMutableDictionary dictionary];
        [pragmaOptions setObject:@"DELETE" forKey:@"journal_mode"];
        [description setOption:pragmaOptions forKey:@"NSQlitePragmaOptions"];
        _persistentContainer.persistentStoreDescriptions=@[description];
        [_persistentContainer loadPersistentStoresWithCompletionHandler:^(NSPersistentStoreDescription *storeDescription, NSError *error) {
            if (error != nil) {
                // Replace this implementation with code to handle the error appropriately.
                // abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.

                /*
                 Typical reasons for an error here include:
                 * The parent directory does not exist, cannot be created, or disallows writing.
                 * The persistent store is not accessible, due to permissions or data protection when the device is locked.
                 * The device is out of space.
                 * The store could not be migrated to the current model version.
                 Check the error message to determine what the actual problem was.
                */
                NSLog(@"Unresolved error %@, %@", error, error.userInfo);
                abort();
            }
        }];
    }
}

return _persistentContainer;}

Я также проверил это:

NSArray *descriptionArray=[_persistentContainer persistentStoreDescriptions];
NSPersistentStoreDescription * description=[descriptionArray objectAtIndex:0];
NSLog(@"%@",description.options);

, и результат NSLog:

{
NSInferMappingModelAutomaticallyOption = 1;
NSMigratePersistentStoresAutomaticallyOption = 1;
NSQlitePragmaOptions =     {
    "journal_mode" = DELETE;
};

, но когда я перезапускаюapp Я всегда нахожу в каталоге приложения все три файла My_App.sqlite, My_App.sqlite-shm и My_App.sqlite-wal.

Почему это не работает?

...