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

你的呢?


当前回答

Cmd + ~(波浪号-看起来很奇怪的按钮…)

在任何打开的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项目模板。

没有多少键盘快捷键,但是源代码中的TODO注释显示在编辑器顶部的方法/函数下拉列表中。

例如:

// TODO: Some task that needs to be done.

在方法和函数的下拉列表中显示,以便您可以直接跳转到它。

大多数Java ide在滚动条中为这些任务标记显示一个标记,这样更好,但这也可以工作。

⌘'来正确格式化(重新缩进)您的代码

编辑:显然重缩进功能(编辑>格式>重缩进)没有默认的快捷方式。我想我很久以前就分配了一个(在Preferences > Key bindings中),甚至不记得了。抱歉误导你了。

User Scripts菜单中有很多好东西,而且添加自己的脚本也相对容易。例如,我添加了一个快捷方式并将其绑定到cmd-opt—在我的代码中插入注释分隔符和#pragma标记来快速分解文件。

# !/bin/sh Echo -n "//================....================ #pragma mark”

当我点击cmd-opt——时,这些行被插入到我的代码中,光标被预先定位为编辑pragma mark组件,该组件显示在符号弹出框中。

通过命令行控制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