随着大量的Xcode新手的涌入,我相信会有很多Xcode的技巧和技巧可以分享。

你的呢?


当前回答

Cmd+Option+O to open a file in a separate window. Can configure Tab to always indent. I frequently use it to indent an entire file. Ctrl+Arrow keys to move between camel case words. If you have OneTwo, you can move from One to Two with Ctrl+Right arrow. You can use emacs bindings, there's even kill ring! I use the Ctrl+w and Cmd+C together when I need to copy two different pieces of text. In the documentation browser, you can restrict your searches to a particular library, e.g., just iOS 4.2 library. This helps me focus on API available only on a particular iOS/Mac version of the SDK. Cmd+Shift+A to build and analyze.

其他回答

能够快速查看可以从超类中重写的所有方法。例如,当扩展UITableViewController时,我只需要输入我的实现:

- ta

然后我按ESC键,看到我的超类中所有以“ta”开头的方法,比如

- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

这也适用于采用协议。

⇧⌘。它会构建和分析,这意味着Xcode会警告你可能的泄漏。

突出显示代码块(重点跟随选择)

从View -> Code Folding -> Focus Follows Selection或controlloptionf激活“Focus Follow Selection”。

这也适用于Python代码,但是在一行中引入空格会使它失效。为了解决这个问题,安装谷歌的Xcode插件,并在它安装的首选项中激活“正确的保存空白”。这将在每次保存文件时清除尾随的空白,因此如果高亮显示出错,您只需保存文件,它就会再次工作。(看,这实际上是两个提示在一起,因为插件的这个特性本身很有用)。

下面是我刚刚写的一些随机Python代码的示例。我使用午夜Xcode语法着色主题。

这对于代码的高嵌套部分非常有帮助,可以跟踪内容在哪里。另外,注意左边,就在行号的右边,这些部分也是有颜色的。这是代码折叠条。如果你把鼠标滑下,它会高亮鼠标下方的部分。这些彩色条都可以折叠,换句话说,代码中高亮显示的部分正是可以折叠的部分。

我不太喜欢xcode中内置的代码格式化/reindent功能,所以我发现使用uncrustify作为代码格式化器非常有用。它可以作为用户脚本使用:http://hackertoys.com/2008/09/18/adding-a-code-beautifier-script-to-xcode/

事实上,我可以使用Emacs作为我的编辑器,Xcode作为我的构建器/调试器……在我看来,这是两全其美。