寻找你所在的行 addPersistentStoreWithType:configuration:URL:options:
addPersistentStoreWithType:configuration:URL:options:
NSURL *storeURL = ...; NSError *error = nil; persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:...]; if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error]) { NSLog(@"Add persistent store failed: %@", error); }
然后加:
NSDictionary *attributes = @{NSFileProtectionKey: NSFileProtectionComplete}; if (![[NSFileManager defaultManager] setAttributes:attributes ofItemAtPath:path error:&error]) { NSLog(@"File protection failed: %@", error); }
请注意,您不能在后台使用数据库,请考虑使用NSFileProtectionCompleteUnlessOpen:
NSFileProtectionComplete
NSFileProtectionCompleteUnlessOpen