gpt4 book ai didi

objective-c - 获取 UIManagedDocument 的 URL

转载 作者:行者123 更新时间:2023-11-29 13:34:16 26 4
gpt4 key购买 nike

目前,我确定文档目录并检索其中的 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,但这是一种用于设置持久存储名称的方法。任何指导表示赞赏。

最佳答案

是的 UIManagedDocumentUIDocument 的具体子类,必须使用 URL 进行初始化。 URL 存储到属性 fileURL(继承自 UIDocument),可以像这样访问:

NSURL* url = myUIManagedDocument.fileURL;

关于objective-c - 获取 UIManagedDocument 的 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11051836/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com