下面是一段相关代码:
NSURL *url = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
url = [url URLByAppendingPathComponent:@"Demo Document"];
UIManagedDocument *document = [[UIManagedDocument alloc] initWithFileURL:url];
if (document.documentState == UIDocumentStateClosed) {
NSLog(@"file is closed");
NSLog(@"%@",[url path]);
NSDate *start = [NSDate date];
[document openWithCompletionHandler:^(BOOL success) {
if (success) {
NSLog(@"finished OPEN");
NSDate *methodFinish = [NSDate date];
NSTimeInterval executionTime = [methodFinish timeIntervalSinceDate:start];
NSLog(@"time = %f",executionTime);
self.managedObjectContext = document.managedObjectContext;
}
}];
}
“文件已关闭”和“完成打开”之间的时间间隔为 16.6 秒。这是正常行为吗?编码不好?还是因为我在模拟器上运行?
我不知道这是否重要,但文件只有 50KB ......