Recommended or Typical UTI for Plain Text Editor App

For the fields listed below, what are the recommended or typical values such that (1) my app can open, edit, and save any ".txt" file and (2) such that other text viewing/editing apps can open the files created by my app? If it matters, my app can view, create, edit, and save UTF-8 text.

Document Types fields Name and Types and all the fields for Imported Type Identifiers. And any other important fields or other things that I should set.

Also, if I upload my app to the App Store and make a mistake on some or all of these, will I be able to correct them?

My knowledge in this area is close to zero, so I'm hoping for minimal technical information, just simple answers if such are possible. I hope you understand.

Accepted Reply

Since public.plain-text is a system-defined UTType, and you want a standard extension (.txt), you don't need to declare either an imported or exported type identifier. You can just specify your document type as public.plain-text directly.

You could use a more specific system-defined type to limit your app to UTF8, but it's probably a better user experience if your plist allows anything that appears to be a text file, then validate the data when you first open the file, to make sure it's a format your can read. Keep in mind that many files end being given the "wrong" extension, and trying to enforce a format precondition may result in obscurely unhelpful errors being presented to the user.

Replies

Since public.plain-text is a system-defined UTType, and you want a standard extension (.txt), you don't need to declare either an imported or exported type identifier. You can just specify your document type as public.plain-text directly.

You could use a more specific system-defined type to limit your app to UTF8, but it's probably a better user experience if your plist allows anything that appears to be a text file, then validate the data when you first open the file, to make sure it's a format your can read. Keep in mind that many files end being given the "wrong" extension, and trying to enforce a format precondition may result in obscurely unhelpful errors being presented to the user.

Thanks Polyphonic!

So, my current understanding is that Document Types, Name could be anything, but I suppose it may be seen by users somewhere. And Types should be public.plain-text. As for Imported Type Identifiers, I'm going with what's shown (generically) in the image below. After changing the Imported Type Identifiers, Identifier as shown, I needed to use the same value in the code created by the Doc App template. See the code below.

I created two test apps using the Doc App template, GreenPurple1 and GreenPurple2, and they both created .txt files and they could (obviously?) open and edit files created by the other app.

And per Polyphonic's recommendation to validate that my app has just opened (only) UTF8 data, I've searched for how this is done and it appears this won't be 10 lines of Swift code or fewer. But if you know otherwise, please share!

import SwiftUI
import UniformTypeIdentifiers

extension UTType {
    static var exampleText: UTType {
        UTType(importedAs: "com.CompanyName.GreenPurple1")
    }
}

This does indeed appear to be correct: Since public.plain-text is a system-defined UTType, and you want a standard extension (.txt), you don't need to declare either an imported or exported type identifier. You can just specify your document type as public.plain-text directly.

After closing my Xcode project, I opened info.plist directly from my project via Finder. I then hovered over "Document types" and selected the tiny minus in a circle to delete that entry. I likewise deleted "Imported Type Identifiers". The only entry I had remaining was "App Uses Non-Exempt Encryption" which I have set to NO.

I also removed this code:

extension UTType {
    static var exampleText: UTType {
        UTType(importedAs: "com.example.plain-text")
    }
}

All seems to working well. Hopefully I didn't make a mess of things. Thanks again Polyphonic.