My NSDocument subclass needs to accept any kind of file

592 views Asked by At

I am building a viewer application, which needs to accept "any" kind of file as the selected file to view. In fact it even should accept folders, because in that case I want to show information relevant about the folder such as number of files and such. Now suppose I decided to use the NSDocument based application architecture to do this. How do I make my application accept any kind of file (and not get these [NSDocumentController reopenDocumentForURL:withContentsOfURL:display:completionHandler:] failed messages?

1

There are 1 answers

0
robject On BEST ANSWER

Based on the discussion: iOS Document/File type associations - wildcard UTI? I managed to get it working (it seems):

  1. Go in Xcode (I am using 4.1) to the "Project Navigator" and select the target application.
  2. Select the "Info" tab
  3. Go to the "Document Types" element in the list. If you used the default project creation it will have your custom document type already filled in.
  4. Now change the Name property to public.item.

Now the application will be able to open any kind of file as its document. One thing to remember is to keep the following (automatically generated during project creation) methods in place. I deleted them, assuming I did not need them, and that created another error:

  1. - (NSData *)dataOfType:(NSString *)typeName error:(NSError **)outError
  2. - (BOOL)readFromData:(NSData *)data ofType:(NSString *)typeName error:(NSError **)outError

and to be able to have folders as your document, add:

  • - (BOOL)readFromFileWrapper:(NSFileWrapper *)fileWrapper ofType:(NSString *)typeName error:(NSError **)outError

It seems to work for now, any additional remarks are welcome.