Search code examples
objective-cmacosuti

How do I make a file that identifies as a custom UTI type?


Right now I have an application that generates an XML file. We'll call it someFile.myapp When my app saves the file and look at it using mdls it has a kMDItemContentType of "dyn.234kdfsjk23jk24234kjfd" How can I get the UTI type of the file to be a custom value like com.mycompany.myapp?


Solution

  • UTIs are linked to extensions via a declaration in your application's Info.plist file. Add a section like so:

    <key>UTExportedTypeDeclarations</key>
    <array>
        <dict>
            <key>UTTypeConformsTo</key>
            <array>
                <string>public.xml</string>
            </array>
            <key>UTTypeDescription</key>
            <string>My Special File Type</string>
            <key>UTTypeIdentifier</key>
            <string>org.myapp.someutiidentifier</string>
            <key>UTTypeTagSpecification</key>
            <dict>
                <key>public.filename-extension</key>
                <array>
                    <string>myapp</string>
                </array>
            </dict>
        </dict>
    </array>