天天看點

xcode使用小技巧

1. 更改公司名稱 (Changing the Company Name )

改變公司名稱, 當你用Xcode建立一 Objective C 源檔案的時候, 通常Xcode會自動生成底下的注釋:

//

// TapDance.h

// Groovilicous

//

// Created by markd on 7/25/08.

// Copyright 2008 __MyCompanyName__. All rights reserved.

//

markd 是你登入Mac系統的名字

__MyCompanyName__ 是你定義的公司名字, 可以通過以下指令在Terminal裡面進行修改名字:

defaults write com.apple.Xcode PBXCustomTemplateMacroDe finitions '{"ORGANIZATIONNAME" = "Length-O- Words.com";}'

Length-O- Words.com就是定義新的公司名稱, 你可以自己替換自己要定義的名稱.

2. Writing Your Code with a Little Help from Xcode

縮進

先選擇一段要編輯的内容,用滑鼠拖動選擇好後:

Command(win鍵盤的Alt) + [       左縮進

Command + ] 右縮進

右鍵 -> Re-Indent Selection 自動編排格式

代碼自動完成

Xcode會記住很多已經存在的名字, 你鍵入字元的時候, 它會根據自己的字典來猜測你要寫的内容, 如果比對成功, 直接敲Tab鍵或者Enter鍵Xcode就幫你完成剩餘的内容. Escape會列出一個下拉清單, 讓你自己有更多的選擇. ctrl+/ 來定位函數的多個占位符參數.

Kissing the Parentheses (括号配對)

Xcode 可以自動配對括号, 而且回自動高亮顯示.

Double click one of the delimeters(")", "]", "}"), and Xcode will select the code between it and its mate.

Mass Edit(批量編輯)

1. 快照(Snapshot)

File -> Make Snapshot 建立快照

File -> Snapshots                   打開快照管理器, 可以恢複之前建立的快照.

2. 查找(Find)

Edit -> Find

3. 編輯在作用域中同名變量(Edit all in Scope)

選擇要編輯的名稱

Edit -> Edit all in Scope

4. 重構(Refactor)

當你重命名一個類的名字的時候, 相應的檔案名也被Rename. 這個功能很好用. Eclipse 有這種功能, VC的VA插件也有, 不過好像它們都不能重名檔案名.

選擇要重命名的類名, 函數名等

Edit -> Refactor

注釋: 很多指令有快捷鍵, 可以利用快捷鍵加快效率, 沒用快捷鍵的, 可以在Perferences裡的key buildings設定指令對應的快捷鍵.

5. Navigating Around in Your Code

下面的快捷鍵不僅僅是适用于Xcode, 而且适用諸如TextEdit, Safari's URL bar 等等, 一般具有編輯功能的都有這張功能(在Mac中)

ctrl + A       将光标移動到目前光标所在行的開始位置

ctrl + E       将光标移動到目前光标所在行的結束位置

ctrl + T       交換目前光标所在為止的詞和此詞的上一個詞的位置.(就是互換倆個詞)

ctrl + K      删除目前光标所在位置到目前行結尾處

ctrl + D       相當于鍵盤的Delete按鍵, 删除後面一個字元.

6. 書簽(Bookmarks)

Edit -> Add Bookmarks (Alt + D)

In the Groups & Files pane,     你能找到Bookmarks, 裡面的你可以點選.

Xcode Keyboard Shortcuts

? 表示: Command(Alt)

?表示: Shift

? 表示: Win

Control表示:Ctrl

Keystroke                                        Description

??E                                                      Expand the editor

?[                                                                Shift the code block to the left

?]                                                                 Shift the code block to the right

Tab                                                             Accept a completion

Esc                                                          Show the completion menu

Control-.                                           (period) Cycle through the completions

Shift-control-.                             (period) Cycle backward through the completions

Control-/                                          Move to the next completion placeholder

Command-control-S      Make a snapshot

Control-F                                     Move the cursor forward

Control-B                                        Move the cursor backward

Control-P                                 Move the cursor to the previous line

Control-N                                 Move the cursor to the next line

Control-A                                         Move the cursor to the beginning of the line

Control-E                                 Move the cursor to the end of the line

Control-T                                 Transpose the characters adjacent to the cursor

Control-D                                Delete the character to the right of the cursor

Control-K                                Delete the line

Control-L                                Center the cursor in the text editor

??D                                                 Show the Open Quickly window

??↑                                                               Open the counterpart file

?D                                                               Add a bookmark

Option–double-click                                Search in documentation

?Y                                                               Run the program with the debugger

??P                                                               Continue (in the debugger)

??O                                                               Step over

??I                                                               Step into

??T                                                               Step out