xcode的使用
# 快捷键
# 导航与搜索
Command Shift - A: Quick Actions(快速操作面板)Command Shift - O:Open Quickly,全局快速查找文件/符号(最常用)Command Shift - F: Find in WorkspaceCommand Shift - J: 在左侧项目导航器(Project Navigator)中定位并高亮当前打开的文件Command - L:跳转到指定行Command Ctrl - J:跳转到符号定义/实现(索引未完成时比Command - 点击更可靠)Command Ctrl - ↑ / Command Ctrl - ↓:切换.h头文件 /.m/.mm实现文件Command Ctrl - ← / Command Ctrl - →:前进/后退(导航历史)Command - 点击:弹出上下文菜单,可查看 Callers(调用者) (opens new window)
# Editor
Command - [ / Command - ]:选中行向左/向右缩进Command Option - [ / Command Option - ]:当前行向上/向下移动Option - 点按:查看选中符号的 Quick Help 提示Ctrl - 1:show releated itemsCtrl - 6:查看当前文件结构(方法/符号列表,可直接输入过滤)- 代码折叠
Command Option - ←:折叠当前代码块(方法、类、if/else 等)Command Option - →:展开当前代码块- 鼠标操作:点击行号左侧的折叠箭头(▽ 展开 / ▷ 折叠)
Control Command - ↑:聚焦当前代码块(Focus),隐藏其他代码,专注当前方法- 折叠/展开所有:菜单栏
Editor→Code Folding→Fold / Unfold
- 代码格式化
Ctrl - I:重新缩进(Re-Indent),格式化选中代码的缩进,或当前行。Xcode 原生只有重新缩进,不会自动调整空格/换行Command - A→Ctrl - I:全选后重新缩进,格式化整个文件- 完整代码格式化(空格、换行、排序等)需使用第三方工具:
- 命令行:
swiftformat <文件或目录>(需先brew install swiftformat) - Xcode 扩展:安装 SwiftFormat for Xcode 后,
Editor→SwiftFormat→Format File - 可在
Settings→Key Bindings中自定义格式化快捷键(如Command Option - L,对齐 Android Studio)
- 命令行:
# 界面与面板
Command - ,:打开偏好设置 →Key Bindings可查看所有快捷键Command - 0:显示/隐藏左侧 Navigator 面板Command Shift - [ / Command Shift - ]:在已打开的 Tab 之间切换
# 构建与调试
Command - R:重新构建Command Shift - K:Clean Build Folder
# iOS 模拟器快捷键
| 快捷键 | 功能 |
|---|---|
Command Shift - H | 按一次 Home 键(返回桌面) |
Command Shift - H(连按两次) | 进入 App Switcher(应用切换器) |
Command - L | 锁定模拟器 |
Command - R | 旋转屏幕 |
Command Shift - S | 截图(保存到桌面) |
Control Command - Z | 模拟 Shake 手势(摇一摇) |
Command - K | 切换键盘显示/隐藏 |
Command - T | 打开 Slow Animations(慢动作动画,调试动画用) |
更多模拟器选项可在模拟器菜单栏
Hardware/Device/Features中查看,快捷键会标注在菜单项右侧。
# 其他
# attach debug process (opens new window)
Attaching to a Running Process
You can use Xcode to attach to, and debug, a program that is already running. You can attach to a program running under Xcode or to any process running on the current computer for which you have a process ID. To attach the debugger to a running process perform one of the following operations:
- Choose a program from the Debug > Attach menu. This menu lists currently running programs launched from Xcode, identified by the program name and the name of the corresponding Xcode project. (This menu also lists other programs running on the system.) To attach to one of these programs, choose it from the menu.
- To attach to any other running process, choose
Debug > Attach > Process ID. Enter the process ID of the process you want to attach to in the dialog that Xcode displays and press Return. - Click the Attach toolbar item in the Run Log window to attach to a program already running in Xcode. Xcode automatically displays this window when you launch a program in Xcode.
When you launch a program from Xcode, you can also have Xcode automatically attempt to attach the debugger to the process when the program crashes. To do so, select the executable for the program, open an inspector, and select the ?Auto-attach debugger on crash? option in the Debugging pane.
# file blame
for a git blame version click Editor->Author as it, sure it moved

# 查看派生类
采取全局搜索的方式 : xxx