Question

Currently, I determine the documents directory and retrieve the URLs within, saving to an array property:

// 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];
    }
}

When I subsequently want the URL for a UIMangedDocument I reference the array. But I suspect that a UIManagedDocument already knows its URL. The closest thing I've found to this is persistentStoreName, but that is a method used to set the name of the persistent store. Any guidance appreciated.

Was it helpful?

Solution

Yep UIManagedDocument is a concrete subclass of UIDocument and must be initialized with a URL. The URL is stored to the property fileURL (inherited from UIDocument) and can be accessed like so:

NSURL* url = myUIManagedDocument.fileURL;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top