How to implement a complex NSDocument-based app that imports and exports non-native file types?

巧了我就是萌 提交于 2019-12-04 13:21:37
  1. The behaviour sounds like a Viewer of the original file because it can not alter the file.

    For exported file types, add these to your application's Info.plist file using the UTExportedTypeDeclarations key value. An example from Font Pestle is below. Font Pestle does not open or edit CSS, but it does export the format:

     <key>UTExportedTypeDeclarations</key>
         <array>
             <dict>
                <key>UTTypeConformsTo</key>
                <array>
                    <string>public.source-code</string>
                    <string>public.utf8-plain-text</string>
                </array>
                <key>UTTypeDescription</key>
                <string>Cascading Style Sheet</string>
                <key>UTTypeIdentifier</key>
                <string>eu.miln.font-pestle.css</string>
                <key>UTTypeReferenceURL</key>
                <string>http://www.w3.org/Style/CSS/</string>
                <key>UTTypeTagSpecification</key>
                <dict>
                    <key>public.filename-extension</key>
                    <array>
                        <string>css</string>
                    </array>
                </dict>
            </dict>
    
  2. Subclassing NSDocumentController is a reasonable place to check for previously imported copies of the file being opened.

    If you find yourself writing hundreds of lines of code in your NSDocumentController subclass, reconsider your design. The subclassing required should be minimal.

  3. Use NSDocument's support for NSFileWrapper.

    NSFileWrapper is designed to help ease the managing bundle based documents. NSDocument and NSFileWrapper will handle saving temporary copies of your untitled documented before the user actively saves or needs to pick a destination for the document.

I highly recommend reading Apple's About the Cocoa Document Architecture and following its guidelines as closely as possible. This will save you time and, hopefully, make maintaining your application easier as Apple evolve their underlying frameworks.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!