UIManagedDocument and additional content

I have a document-based application (several documents, each of which has its own permanent data storage). I am using UIManagedDocument to develop it.

Each document is a drawing, and I want to keep a preview ( UIImage ) of each drawing.

As I want to show scrollView with all the previews, I think I should not put the preview inside the database, so I use the UIManagedDocument supplemental content UIManagedDocument as described.

I have a couple of questions:

  • What use does the parameter "absoluteURL" have in additionalContentForURL:error: :? This is not used in the example I'm connected.

  • How to get a preview without opening a document? At the moment I am doing this:

.

 NSString* docName = [[[DocumentStore sharedStore] documentsList] objectAtIndex:indexPath.row]; NSString* dataDirectory = [FileUtils privateDataDirectory]; NSString *dataPath = [dataDirectory stringByAppendingPathComponent:docName]; NSString *imagePath = [dataPath stringByAppendingPathComponent:@"AdditionalContent/thumb.png"]; UIImage * preview = [UIImage imageWithContentsOfFile:imagePath]; 

... but I'm not sure if this is the best way to do this.

+4
source share
1 answer
  • The absoluteURL parameter in additionalContentForURL:error: gives you the absolute URL to which additional content will be written.

    For most use cases, this is not a particularly necessary parameter, since you do not need to know where this data will be written, but it can be useful as an identifier in some unclear cases of use with the global content management system regardless of the document (although, probably, it was would not be a very complex structure)

  • The method you are currently using to get document previews should be great if you take precautions to prevent your application from crashing or exhibiting undefined behavior, if the preview resource does not exist in the path where you expect it will be for some reason.

    Another way to get a preview is to load each document, initialize it, implement readAdditionalContentFromURL:error: in the document class to read the preview and put it into a property, then get the value of this property and use it as a preview. However, this will require loading each individual document into memory in order to get a preview, so I would not recommend doing this, as this would have serious performance implications.

For a general guide to handling additional content in a UIManagedDocument see this answer to this question .

0
source

All Articles