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

你的呢?


当前回答

使用AppKiDo浏览文档。

在Xcode中使用Accessorizer来完成一堆单调、重复的任务。

其他回答

我已经为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项目模板。

Xcode支持文本宏,可以通过编辑菜单末尾的插入文本宏菜单调用。它们也可以使用Code Sense (Xcode的代码补全技术)来调用。

例如,键入键序列pi m control-period将插入#import "file"到你的代码中,file作为一个可编辑的标记,就像代码完成一样。

普拉格玛市场

例子:

#pragma mark === Initialization ===

将这一行写在所有初始化方法之上,将在编辑器上方的下拉菜单中生成一个漂亮的标题。

开很快

Shift + cmd + D 开始输入你想打开的文件名。如果你在寻找框架头文件,这很酷。它们也有很好的注释,有时是文档的附加信息。

ESC

例如,当文本光标指向一个不完整的方法名时,按ESC键。它将搜索所有可能适合的内容,并且您可以快速完成非常大的方法名。如果您不能准确地记住一个方法的名称,这也很好。只需按ESC键。

我认为这些是我迄今为止知道的最好的。

(从被Stack Overflow用户删除的问题迁移过来,谢谢。)

使用类浏览器显示继承的方法

Apple's API reference documentation does not show methods inherited from a superclass. Sometimes, though. it's useful to be able to see the full range of functionality available for a class -- including a custom class of your own. You can use the Class Browser (from the Project menu) to display a flat or hierarchical list of all the classes related to a current project. The upper pane on the right hand side of the browser window shows a list of methods associated with the object selected in the browser. You can use the Configure Options sheet to select "Show Inherited Members" to show inherited methods as well as those defined by the selected class itself. You click the small book symbol to go to the corresponding documentation.

使用^T来交换前面两个字母

这适用于所有Cocoa应用程序,但我尤其喜欢在编码时使用它。使用^T (Control-T)来交换插入符号旁边的两个字母,或者当插入符号在末尾时,交换插入符号前面的两个字母。例如:

fi^T

... 就变成:

if

... 这是我经常犯的错别字。