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

你的呢?


当前回答

Xcode代码格式化…当你想要编写代码时,它是你需要的东西之一吗 可读性和外观良好。

您可以自己格式化代码,也可以使用脚本节省时间。

一个好方法是…使用Uncrustify。在Xcode中的代码格式化中有解释。

其他回答

在Xcode的Groups and Files窗格中选择Group,然后Edit > Sort by > Name。

您可能希望在组的上下文菜单中找到它,但它不在那里。

Credit:在Xcode中排序文件。

构建成功/失败噪音;从术语:

defaults write com.apple.Xcode PBXBuildSuccessSound ~/Library/Sounds/metal\ stamp.wav
defaults write com.apple.Xcode PBXBuildFailureSound ~/Library/Sounds/Elephant

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.

右键单击函数中的变量,然后单击edit all in scope。自从我发现了这个,我就一直在用它。

ctrl⌘T

我刚刚发现了如何改变文本宏中使用的缩进行为:

例如,如果你和我一样,不喜欢这个:

if (cond) {
  code;
}

但我更喜欢这样:

if (cond)
{
  code;
}

然后你可以通过在终端中设置以下默认值来全局(所有语言)更改此设置:

defaults write com.apple.Xcode XCCodeSenseFormattingOptions -dict-add BlockSeparator "\n"

这个问题已经困扰我很多年了,我希望其他人也会感兴趣。

这个特性的文档可以在Xcode用户默认参考中找到