Multiple Type in MacOS Document-based App

I try to create an native MacOS document-based- app with AppKit

this app should can read and write many different type of file like HTML, CSS, Javascript, PHP, Java and so on.

The problem is with css file. in other post of forum is written that The correct type is public.css.

but if I import type that is conform to public.css, when I run the app and look for an css file to open, that file doesn't selectable and I get error:

An NSDocumentController returned nil when sent -fileExtensionsFromType:@"com.example.css". See the info about new support for UTIs in the Leopard AppKit release notes.

p.s. I've retry to put the same settings and the error doesn't come out but the file still unselectable in open dialog panel

can someone help me?

The Open and Save panels for an app that uses NSDocument are initially configured to only allow opening and saving files of your document type. If you want to read and write multiple file types, you must create imported and exported UTIs (Uniform Type Identifiers) for those file types. NSDocument has a readableTypes and a writableTypes property for the types a document type supports, but they provide only get methods. You can't set them in your app's code.

To add imported and exported UTIs for your document type, take the following steps:

  1. Open the project editor by selecting the project from the left side of the project window.
  2. Select your app target from the left side of the project editor.
  3. Click the Info button at the top of the project editor.
  4. Click the disclosure triangle next to Exported Type Identifiers to access and add exported UTIs.
  5. Click the disclosure triangle next to Imported Type Identifiers to access and add imported UTIs.

In SwiftUI reading and writing multiple file types is easier. SwiftUI documents have readableContentTypes and writableContentTypes properties where you can specify an array of UTTypes your file can read and write.

Multiple Type in MacOS Document-based App
 
 
Q