0

I have created a document based app that needs to open xml text files with a particular extension. When I created the project in Xcode using the NSDocument template I specified the extension I wanted and everything was working fine.

Following the Apple guide on how to build document based apps I went to edit the Info.plist file to add the details of the UTI that were missing before. Suddenly my app stopped opening files with the extension I want and in fact stopped opening any file. Also when I try to save a file the save dialog doesn't suggest any extension any more.

When I save a file and run the command mdls from the terminal I get

kMDItemContentTypeTree         = (
    "public.data",
    "public.item"
)

instead of public.xml I set for the UTI in the Info.plist. It seems that my app stopped recognising the informations stored in the Info.plist. Is there anything I have to connect in Xcode in order to have this working?

Here is the relevant parts of my Info.plist file:

<key>CFBundleDocumentTypes</key>
<array>
    <dict>
        <key>CFBundleTypeExtensions</key>
        <array>
            <string>xmds</string>
        </array>
        <key>CFBundleTypeIconFile</key>
        <string>AppIcon</string>
        <key>CFBundleTypeName</key>
        <string>XMDS Script</string>
        <key>CFBundleTypeOSTypes</key>
        <array>
            <string>xmds</string>
        </array>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>com.dedalus.degs</string>
        </array>
        <key>NSDocumentClass</key>
        <string>Document</string>
    </dict>
</array>
<key>UTExportedTypeDeclarations</key>
<array>
    <dict>
        <key>UTTypeConformsTo</key>
        <array>
            <string>public.xml</string>
        </array>
        <key>UTTypeDescription</key>
        <string>XMDS Script</string>
        <key>UTTypeIconFile</key>
        <string>AppIcon</string>
        <key>UTTypeIdentifier</key>
        <string>com.dedalus.degs</string>
        <key>UTTypeTagSpecification</key>
        <dict>
            <key>com.apple.ostype</key>
            <array>
                <string>xmds</string>
            </array>
            <key>public.filename-extension</key>
            <array>
                <string>xmds</string>
            </array>
        </dict>
    </dict>
</array>
Jacopo
  • 981
  • 1
  • 11
  • 24
  • I have tried creating a new document based project using Xcode template. At the beginning the app opens and saves documents in the extension I specified in the template. As soon as I enter an identifier for the document type in the Project's Target Info setting everything breaks down. – Jacopo Aug 24 '12 at 00:33

1 Answers1

3

I used the Project's Target Info setting to set the Document Type and UTI instead of the Info.plist file in Xcode 4.2 and 4.4. This pulls from the Info.plist file and modifies it after you change it. Try using that instead.

The Document Type defines the class that will handle the extension and the extension. The Exported UTIs represent the extensions for which your app is authoritative. See this Stackoverflow question: What are “Imported UTIs” in Xcode 4?

My Exported UTIs conform to public.data ("Base type for any sort of simple byte stream, including files and in-memory data"). If you use an identifier, make sure it is the same in both the Document Type and Exported UTIs.

Community
  • 1
  • 1
Greg Walters
  • 181
  • 5
  • That's exactly how I set those up. I just thought that pasting the Info.plist was easier to read. – Jacopo Aug 23 '12 at 21:56