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。
谢谢
3条答案
按热度按时间lkaoscv71#
要禁用WAL模式,请将journal_mode设置为DELETE
ego6inou2#
来自Apple技术文稿:Technical Q&A QA1809
编辑2020:
快速用户界面+ iOS 14(Xcode 12测试版6)
当您使用SwiftUI创建新项目并选中CoreData模板时,您的新项目在 Persistence.swift 文件中包含以下代码:
现在,您可以在init容器(
container = NSPersistentContainer(name: "db_name")
)之后添加以下代码块e5nqia273#
对于Swift 2,它将如下所示: