随着大量的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项目模板。

其他回答

你可以让Xcode在Info上运行预处理器。plist文件:

        <key>CFBundleShortVersionString</key>
    #ifdef DEBUG
        <string>1.0 (debug)</string>
    #else
        <string>1.0</string>
    #endif

详情见http://developer.apple.com/technotes/tn2007/tn2175.html。

通过命令行控制Xcode的文本编辑器:xed

> xed -x                # open a new untitled document
> xed -xc foo.txt       # create foo.txt and open it
> xed -l 2000 foo.txt   # open foo.txt and go to line 2000

# set Xcode to be your EDITOR for command line tools
# e.g. for subversion commit
> echo 'export EDITOR="xed -wcx"' >> ~/.profile

> man xed               # there's a man page, too

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

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

fi^T

... 就变成:

if

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

链接一个新的框架

(在Groups and Files窗格中,打开Targets披露三角形以显示与项目相关的目标。)

在Groups and Files窗格中,双击当前项目目标以显示target Info面板。 在Info面板中,选择General选项卡。下方窗格显示当前链接的框架。 通过按面板左下角的+按钮,并从出现的工作表中显示的列表中选择,添加一个新框架。(重要的是,表格中的列表只显示了与目标相关的框架…)

(这在两年前是不可用的,但是值得指出的是,比起在文件系统中找到框架并将其拖放到项目中,它可以节省大量的时间……)

完整的快捷方式列表可以在这里找到:http://iphonehuston.blogspot.com/2009/08/shortcuts-for-xcode.html