目前,我确定文档目录并检索其中的 URL,保存到数组属性:
// Returns an array of all the Vacations on file.
- (void)findVacationsOnFile
{
self.vacationURLs = [[NSArray alloc] init];
// Identify the documents folder URL.
NSFileManager *fileManager = [[NSFileManager alloc] init];
NSError *errorForURLs = nil;
NSURL *documentsURL = [fileManager URLForDirectory:NSDocumentDirectory
inDomain:NSUserDomainMask
appropriateForURL:nil
create:NO
error:&errorForURLs];
if (documentsURL == nil) {
NSLog(@"Could not access documents directory\n%@", [errorForURLs localizedDescription]);
} else {
// Retrieve the vacation stores on file.
NSArray *keys = [NSArray arrayWithObjects:NSURLLocalizedNameKey, nil];
self.vacationURLs = [[NSFileManager defaultManager] contentsOfDirectoryAtURL:documentsURL
includingPropertiesForKeys:keys
options:NSDirectoryEnumerationSkipsHiddenFiles
error:nil];
}
}
当我随后需要 UIMangedDocument 的 URL 时,我引用了该数组。但我怀疑 UIManagedDocument 已经知道它的 URL。我发现与此最接近的是 persistentStoreName,但这是一种用于设置持久存储名称的方法。任何指导表示赞赏。
最佳答案
是的 UIManagedDocument
是 UIDocument
的具体子类,必须使用 URL 进行初始化。 URL 存储到属性 fileURL(继承自 UIDocument),可以像这样访问:
NSURL* url = myUIManagedDocument.fileURL;
关于objective-c - 获取 UIManagedDocument 的 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11051836/