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

你的呢?


当前回答

我刚从Windows世界来到Xcode(就像其他许多人一样),我遇到的第一个怪招就是尝试用TAB键“缩进选定的文本块”。

通常,当使用Windows编辑器时,您选择一个文本块,无论何时按TAB(或shift TAB)键,所选的文本都会右/左跳转。然后,一旦确定了文本的新位置,就停止按TAB键。

好吧,在Xcode中,这是完全不同的,因为当你按TAB键时,整块文本消失了,留给你一张愚蠢的脸,内心有些愤怒……

但后来,出于偶然或直觉或其他原因,有一天我发现了一些变通方法,可以达到你在正确的窗口编辑器下可能得到的相同效果。 步骤如下:

Select the text block as you might do under Windows. Instead of pressing TAB, leave your instincts away, and "copy the text block" (typically CTRL+C (yuck)). Then, without deselecting the text, (pressing SHIFT if needed), extend the beginning of the selection and place it on the position you would like your new text to appear. Paste the beforementioned text (typically CTRL+V (yuck again)). Result: The previous text block gets substituted by "the new" one (of course, itself), but the "auto indent" capabilities of Xcode (or someone else, who cares), will auto place the text starting onto the new position we chose in step 3. A big smile appears on your face.

这有点棘手,但当你习惯了,你会发现自己经常使用它。

享受! !

其他回答

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

链接一个新的框架

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

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

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

按左/按右键导航变量或方法名中的单词。没有这个我活不下去。

Control+R将所选文本作为shell脚本执行,该脚本将在选择后返回粘贴的输出!

“Ctrl+左/右箭头”进行字内文本导航。我使用这个特性将光标从变量中的一个“驼峰”跳转到下一个。