You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使Xcode创建的macOS文档类App识别.txt与.text文件

解决macOS文档类应用识别.txt/.text文件的步骤
  • 直接编辑Info.plist文件(避开Xcode界面的bug)

    • 找到项目里的Info.plist文件,右键选「Open As」→「Source Code」
    • 替换或添加CFBundleDocumentTypes数组的内容,配置txt和text文件的关联:
      <key>CFBundleDocumentTypes</key>
      <array>
          <dict>
              <key>CFBundleTypeName</key>
              <string>Plain Text Document</string>
              <key>CFBundleTypeRole</key>
              <string>Editor</string>
              <key>LSHandlerRank</key>
              <string>Owner</string>
              <key>LSItemContentTypes</key>
              <array>
                  <string>public.plain-text</string>
                  <string>public.text</string>
              </array>
          </dict>
      </array>
      
    • 保存文件,回到Xcode,文档类型配置就生效了
  • 同步文档类的代码配置

    • 找到项目默认的文档类(比如OpenTextDocDocument),确保readableContentTypes属性返回正确的UTI类型:
      Swift版本:
      override class var readableContentTypes: [UTType] {
          return [.plainText, .text]
      }
      
      Objective-C版本:
      + (NSArray<UTType *> *)readableContentTypes {
          return @[UTTypePlainText, UTTypeText];
      }
      
  • 清理重建项目

    • 点击「Product」→「Clean Build Folder」(快捷键⇧⌘K)
    • 重启Xcode后重新运行项目,此时打开文件对话框里的.txt和.text文件就能正常选中了

内容的提问来源于stack exchange,提问作者jsbox

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.19 09:33:13