Получение URL-адреса UIManagedDocument

В настоящее время я определяю каталог документов и извлекаю 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];
    }
}

Когда мне впоследствии нужен URL-адрес для UIMagedDocument, я ссылаюсь на массив. Но я подозреваю, что UIManagedDocument уже знает свой URL. Самое близкое, что я нашел к этому, — это persistStoreName, но это метод, используемый для установки имени постоянного хранилища. Любое руководство приветствуется.


person Michael Mangold    schedule 15.06.2012    source источник


Ответы (1)


Да, UIManagedDocument является конкретным подклассом UIDocument и должен быть инициализирован URL-адресом. URL-адрес хранится в свойстве fileURL (унаследованном от UIDocument), и к нему можно получить доступ следующим образом:

NSURL* url = myUIManagedDocument.fileURL;
person Patrick Borkowicz    schedule 15.06.2012