随着大量的Xcode新手的涌入,我相信会有很多Xcode的技巧和技巧可以分享。
你的呢?
随着大量的Xcode新手的涌入,我相信会有很多Xcode的技巧和技巧可以分享。
你的呢?
当前回答
代码自动完成
其他回答
⇧⌘。它会构建和分析,这意味着Xcode会警告你可能的泄漏。
在shell构建阶段,您可以使用以下格式写入stderr:
<filename>:<linenumber>:错误|警告|备注:<消息>\n .
它与gcc用来显示错误的格式相同。filename:linenumber部分可以省略。根据模式(错误,警告,注意),Xcode将显示你的消息与红色或黄色徽章。
如果你包含一个绝对文件路径和行号(如果错误发生在一个文件中),双击构建日志中的错误让Xcode打开文件并跳转到行,即使它不是项目的一部分。非常方便。
我已经为NSObject, UIView和UIViewController创建了自己的文件模板,所以当我创建新类时,这些文件都设置了私有部分,并在init和dealloc中记录类的地址。
示例(命名为'test'的NSObject派生类将像这样开始):
//=====================================================
// Private Interface
//=====================================================
@interface test (private)
@end
//=====================================================
// Public Implementation
//=====================================================
@implementation test
- (void)dealloc {
NSLog(@">>> Dealloc: test [0x%X]", self);
[super dealloc];
NSLog(@"<<< Dealloc: test");
}
- (id) init
{
self = [super init];
if(self) {
NSLog(@">>> Alloc: test [0x%X]", self);
}
return self;
}
@end
//=====================================================
// Private Implementation
//=====================================================
@implementation test (private)
@end
这方面有很多可用的资源,例如Cocoa dev:设计自己的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.
我不太喜欢xcode中内置的代码格式化/reindent功能,所以我发现使用uncrustify作为代码格式化器非常有用。它可以作为用户脚本使用:http://hackertoys.com/2008/09/18/adding-a-code-beautifier-script-to-xcode/