1. Declare file types as document types
As part of the Xcode project, add a Document Type for all file formats supported by your application. Set the Role of each type depending on your application capabilities:
- Mark file types with read / write support as Editor ;
- Mark import only file types as View .
Set the Class for the type of document with which you want to process each file type. A single document class can handle several types of files.
The following example shows three types of files: font-pestle, otf, and ttf. The first, font-pestle, is its own application format. This type has the role of Editor .
The other two formats, otf and ttf, can be imported but not written by the application; therefore they are marked as Viewer .

2. Additional file types in a subclass of NSDocument
When adding document types, the application will automatically allow users to open files of the specified types.
You need to add the file type processing code to the document class. Ideally, add the branch code to the readFromData:ofType:error: method:
- (BOOL)readFromData:(NSData*)someData ofType:(NSString*)typeName error:(NSError**)outError { if ([NSWorkspace.sharedWorkspace type:@"eu.miln.font-pestle" conformsToType:typeName] == YES) { // read native format } else if ([NSWorkspace.sharedWorkspace type:@"public.opentype-font" conformsToType:typeName] == YES) { // read import only format // disassociate document from file; makes document "untitled" self.fileURL = nil; // associate with primary file type self.fileType = @"eu.miln.font-pestle"; } else // ... }
Important self.fileURL = nil; . By setting fileURL to nil, you say that the document is not associated with any file on disk and should be considered as a new document.
To enable automatic saving, implement the NSDocument autosavingFileType method to return the main file type.
source share