1

現在、ドキュメント ディレクトリを特定し、その中の 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];
    }
}

その後、UIManagedDocument の URL が必要な場合は、配列を参照します。しかし、UIManagedDocument は既にその URL を知っているのではないかと思います。私が見つけた最も近いものはpersistentStoreNameですが、これは永続ストアの名前を設定するために使用されるメソッドです。任意のガイダンスをいただければ幸いです。

4

1 に答える 1

1

うんUIManagedDocumentはの具体的なサブクラスでUIDocumentあり、URLで初期化する必要があります。URLはプロパティfileURL(UIDocumentから継承)に保存され、次のようにアクセスできます。

NSURL* url = myUIManagedDocument.fileURL;
于 2012-06-15T13:52:51.007 に答える