我正在使用这个博客: http: //www.adevelopingstory.com/blog/2012/03/core-data-with-a-single-shared-uimanageddocument.html为单例创建单UIManagedDocument
例。这是相关的代码BetterDatabase
//In BetterDatabase
typedef void (^OnDocumentReady) (UIManagedDocument *document);
- (void)performWithDocument:(OnDocumentReady)onDocumentReady
{
void (^OnDocumentDidLoad)(BOOL) = ^(BOOL success) {
onDocumentReady(self.document);
};
if (![[NSFileManager defaultManager] fileExistsAtPath:[self.document.fileURL path]]) {
[self.document saveToURL:self.document.fileURL
forSaveOperation:UIDocumentSaveForCreating
completionHandler:OnDocumentDidLoad];
} else if (self.document.documentState == UIDocumentStateClosed) {
[self.document openWithCompletionHandler:OnDocumentDidLoad];
} else if (self.document.documentState == UIDocumentStateNormal) {
OnDocumentDidLoad(YES);
}
}
//In other class
[[BetterDatabase sharedDocumentHandler] performWithDocument:^(UIManagedDocument * document) {
//Do stuff 1
//Do stuff 2
}];
我的问题: UIManagedDocument 什么时候可以自动关闭?即,文档是否有可能在第 1 行和第 2 行之间关闭(由 OS/SDK)?如果用户最小化 iPhone 应用程序然后再次打开它会怎样?会UIManagedDocument
被关闭吗?
另一种表达方式是:当我仍然有一个强指针指向它时,它会永远关闭吗?UIManagedDocument