gpt4 book ai didi

core-data - 如何禁用 WAL 日志模式

转载 作者:行者123 更新时间:2023-12-03 14:45:59 24 4
gpt4 key购买 nike

https://developer.apple.com/library/ios/releasenotes/DataManagement/WhatsNew_CoreData_iOS/

我在禁用日志模式时遇到问题。

我的代码是:

static NSManagedObjectContext *managedObjectContext(){
static NSManagedObjectContext *context = nil;
if (context != nil) {
return context;
}

NSString * const NSSQLitePragmasOption;

NSSQLitePragmasOption : @{ @"journal_mode" : @"DELETE" };


@autoreleasepool {
context = [[NSManagedObjectContext alloc] init];

NSPersistentStoreCoordinator *coordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:managedObjectModel()];
[context setPersistentStoreCoordinator:coordinator];

NSString *STORE_TYPE = NSSQLiteStoreType;

NSString *path = @"ExerciseDB";
NSURL *url = [NSURL fileURLWithPath:[path stringByAppendingPathExtension:@"sqlite"]];





NSError *error;
NSPersistentStore *newStore = [coordinator addPersistentStoreWithType:STORE_TYPE configuration:nil URL:url options:NSSQLitePragmasOption error:&error];

if (newStore == nil) {
NSLog(@"Store Configuration Failure %@", ([error localizedDescription] != nil) ? [error localizedDescription] : @"Unknown Error");
}
}
return context;
}

我将如何禁用日志模式 WAL。

谢谢

最佳答案

要禁用 WAL 模式,请将 journal_mode 设置为 DELETE

NSMutableDictionary *pragmaOptions = [NSMutableDictionary dictionary];
[pragmaOptions setObject:@"DELETE" forKey:@"journal_mode"];

NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption, [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, pragmaOptions, NSSQLitePragmasOption, nil];
[_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:options error:&error]

关于core-data - 如何禁用 WAL 日志模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20062197/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com