When I thought about making an image viewer, I was lightly addicted to it with my first move, so some people may stumble on the same thing. The environment is Xcode 12.3.
This is natural, so the explanation is omitted.
Register the file in Target-> Info-> Document Types.
For Class, specify the "Document" class that is automatically created when the project is created.
Specify UTI for Identifier. I can't find any information about Apple's home about what kind of character string to specify, but a list is given on the following site. http://potting.syuriken.jp/potting_conv/understanding_utis_J/chapter4.html
Below is an example for opening an image file.
It seems that the "Document" class that inherits NSDocument cannot be used as it is in Swift-based apps, so it is necessary to add a line using @objc. (I couldn't find this information easily ...) Specifically, it looks like this.
@objc(Document) //add to
class Document: NSDocument {
...
At this point, you can select the file, so add the actual reading process. By default, the following methods are called.
override func read(from data: Data, ofType typeName: String)
If you want to get the file path, override the following method.
override func read(from: URL, ofType: String)