一种在Xcode中自动组织#imports的方法 [英] A way to automatically organize #imports in Xcode

查看:174
本文介绍了一种在Xcode中自动组织#imports的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我喜欢Eclipse中的Organize Imports命令来隐式添加和删除导入到源文件中的类(如在Java或ActionScript中)。

I love the "Organize Imports" command in Eclipse to implicitly add and remove classes imported into a source file (as in Java or ActionScript).

是否有在Xcode中命令更新基于文件中引用的类的.m Objective-C文件顶部的 #import 指令?

Is there a command in Xcode to update the #import directives at the top of.m Objective-C files based on the classes referenced within the file?

推荐答案

您可以通过创建Automator操作并在Xcode中以及Mac OS X中的任何位置使用它来完成此操作。为此,请执行以下操作:

You can do this by creating an Automator action and use that in Xcode as well as everywhere in Mac OS X. To do that, do the following:


  1. 启动Automator - >新

  2. 选择服务

  3. 添加运行shell脚本操作

  4. 使用 sort | uniq 作为脚本并检查输出替换所选文本复选框

  5. 保存并为其命名(例如sort& unique)

  6. 选中输出替换所选文本

  1. Start Automator -> New
  2. Choose "Service"
  3. add a "run shell script" action
  4. use sort | uniq as the script and check the "output replaces selected text" checkbox
  5. save and give it a name (e.g. "sort & unique")
  6. check "Output replaces selected text"

保存后,您只需选择导入即可Xcode,右键单击并选择排序和唯一操作来组织导入。

After you saved it, you can just select your imports in Xcode, right click and choose your "sort & unique" action to organize your imports.

这不如Eclipse或IntelliJ中的组织导入操作好,因为它不会删除未使用的东西等但它总比没有好。

This is not as good as the organize import actions in Eclipse or IntelliJ, because it doesn't removes unused stuff etc. but it's better than nothing.

PS:从WWDC 2012会话中获得 - 会话402与Xcode一起高效工作(从6开始: 15)

PS: Got that from WWDC 2012 Sessions - Session 402 Working Effeciently with Xcode (starting at 6:15)

编辑

我开始使用Objective-C IDE AppCode来自JetBrains,它具有组织进口等功能。你应该看一下: http://www.jetbrains.com/objc/

I started using AppCode, the Objective-C IDE from JetBrains, and it has features like "organise imports". You should check it out: http://www.jetbrains.com/objc/.

这篇关于一种在Xcode中自动组织#imports的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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