我在 coreData 应用程序中为我的 - (NSPersistentStoreCoordinator *)persistentStoreCoordinator 编写了这段代码。我使用 xCode 的 Master-Detail Application 模板来创建应用程序...
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator
{
if (__persistentStoreCoordinator != nil) {
return __persistentStoreCoordinator;
}
NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"Notes2.sqlite"];
NSError *error = nil;
__persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
if (![__persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error]) {
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
NSString *urlString = [storeURL absoluteString];
NSDictionary *fileAttributes = [NSDictionary dictionaryWithObject:NSFileProtectionComplete forKey:NSFileProtectionKey];
if (![[NSFileManager defaultManager] setAttributes:fileAttributes ofItemAtPath:urlString error:&error])
{
// Handle error
}
return __persistentStoreCoordinator;
}
如何测试并知道我的 sqlite 是否打开了 NSFileProtectionComplete?
我锁定了模拟器,但是当我在 Finder 中双击文件时,该文件仍然可读。