如何让 Xcode 将自定义文件扩展名识别为 Objective-C 以进行语法高亮显示? [英] How to make Xcode recognize a custom file extension as Objective-C for syntax highlighting?

查看:102
本文介绍了如何让 Xcode 将自定义文件扩展名识别为 Objective-C 以进行语法高亮显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想让 Xcode 4 将自定义文件扩展名(例如 *.lx)识别为 Objective-C,用于语法突出显示和缩进.如何让工具自动执行此操作?

解决方案

Xcode 根据文件的 或在 Xcode 的 Info.plist 中导出的那些.

  • 将扩展"字段设置为要与新 UTI 关联的以逗号分隔的扩展列表.
  • 通过按回车键或将焦点移动到其他字段,将更改提交到最后一个字段.
  • 构建并运行应用程序以将其注册到 Launch Services.
  • 重启 Xcode.
  • Xcode 现在应该对具有指定扩展名的文件使用适当的语法突出显示.

    如果这不起作用,请检查构建的应用程序的 Info.plist 以确保所有预期信息都在那里,没有任何尾随空格.您还可以使用 lsregister 来检查 UTI 是否已注册:

    /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -dump

    在输出中搜索您的 UTI 标识符并验证它是否存在且处于活动状态.

    I'd like to get Xcode 4 to recognize a custom file extension (e.g. *.lx) as Objective-C for syntax highlighting and indentation purposes. How do I get the tool to automatically do this?

    解决方案

    Xcode determines how to represent a file in its user interface based on the file's Uniform Type Identifier. As far as I know it's not possible to add additional file extension tags to an existing UTI, but you can declare a new UTI that conforms to the type you want to map to. The system will then associate the specified file extension(s) with your new UTI and through conformance Xcode and every other UTI-aware application will recognize the files as source code of the mapped type.

    You may want to give some thought to where to declare to the new UTI. For example, if files of this type are being created by a tool the bundle for that tool would be the most appropriate location. In the absence of a better alternative you can create a stub application bundle and declare the new UTI there:

    1. Create a new Cocoa Application project in Xcode.
    2. In project settings, select the application target, then the Info tab.
    3. Create a new Exported UTI.
    4. Set the Identifier field to a unique name using reverse DNS notation for a domain that you control. For example, com.yourdomain.objective-c-source.
    5. Set the Conforms To field to the UTI that you want to map to, such as public.objective-c-source. You can find this by browsing the list of system-declared UTIs or those exported in Xcode's Info.plist.
    6. Set the Extensions field to the comma-separated list of extensions that you want to associate with the new UTI.
    7. Commit the change to the last field by pressing return or moving the focus to a different field.
    8. Build and run the application to register it with Launch Services.
    9. Restart Xcode.

    Xcode should now use appropriate syntax highlighting for files with the specified extension(s).

    If this doesn't work, check the Info.plist of the built application to ensure that all of the expected information is there without any trailing whitespace. You can also check that the UTI has been registered using lsregister:

    /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -dump
    

    Search the output for your UTI's identifier and verify that it is present and active.

    这篇关于如何让 Xcode 将自定义文件扩展名识别为 Objective-C 以进行语法高亮显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆