Xcode 4 的隐藏功能
现在 Xcode 4 已正式发布,是时候跟进我之前的问题了:Xcode 的隐藏功能
那么它们是什么?那些隐藏的 Xcode 4 小提示和信息是什么?您离不开的小贴士?
请将您的提示限制为那些新的且特定于 Xcode 4 的提示!
Now that Xcode 4 is officially released it's time for a follow up to my previous question: Hidden Features of Xcode
So what are they? What are those hidden little Xcode 4 hints & tips that you can't live without?
Please limit your tips to those that are new and specific to Xcode 4!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(23)
如果您希望代码看起来和运行时一样好,那么您无疑使用了
#pragma mark -
和#pragma mark
来提供良好的视觉分组在 Xcode 类下拉列表中。 Xcode 4 现在将它们组合成一个#pragma mark -
。有关编译指示标记的更多信息。
If you like your code to look as good as it runs, you've undoubtedly used
#pragma mark -
and#pragma mark <name>
to provide a nice visual grouping in the Xcode class dropdown list. Xcode 4 now combines these into a single#pragma mark - <name>
.More on pragma mark.
shift-cmd-opt 单击一个符号可以让您准确地告诉 Xcode 您在 UI 中的哪个位置想要打开导航到的文件。
cmd-ret 使版本编辑器/助手(右侧窗格)消失
shift-cmd-Y 隐藏调试器
cmd-0 隐藏导航器(左窗格)
cmd -[1..n] 在左侧导航器之间切换
cmd-opt-[1..n] 在实用程序之间切换(通常在右侧)
ctrl-[1..n]在编辑器中各个相关文件之间切换
总体而言,Xcode 4 尝试使热键保持一致。 Cmd 用于主线命令。添加修饰符适用于专注于某一特定子功能的类似命令。
(这些只是我想到的四个我经常使用的最受关注的快捷方式!我确信随着时间的推移,随着我的工作流程被重构为新的热点,它会发生变化。)
shift-cmd-opt click on a symbol lets you tell Xcode exactly where in the UI you want the navigated-to file to open.
cmd-ret makes the version editor / assistant (the right hand pane) go away
shift-cmd-Y to hide the debugger
cmd-0 to hide the navigator (left pane)
cmd-[1..n] switch between navigators on left
cmd-opt-[1..n] switch between utilities (thing generally on right)
ctrl-[1..n] switch between various related files in the editor
Overall, Xcode 4 tries to keep things consistent w/the hot keys. Cmd is for mainline commands. Adding modifiers is for analogous commands focused on one particular sub-feature.
(These are just the four that come to mind as the my most pounded upon shortcuts that I'm using constantly! I'm sure it'll change over time as my workflow is refactored into the new hotness.)
Xcode 4 添加了新的“代码片段”功能,可通过“查看”>“代码片段”访问。公用事业>代码片段库。要添加新的代码片段,请在编辑器视图中选择一些文本并将其拖到代码片段库中。您可以拖出一个代码片段并将其放入代码中来使用它,或者更方便地为其分配一个完成快捷方式。
当您输入这一系列字母时,它会在您输入代码时自动显示在代码完成弹出菜单中。例如,在许多其他内容中,我设置了一个片段,以便输入“svk”将扩展为
setValue:<#value#> forKey:<#key#>
。这可以节省大量的打字和/或在自动完成菜单中查找您最常使用的方法和其他代码表达式的时间。 Xcode 附带了一堆内置的代码片段,它们也非常方便。Xcode 4 adds a new "Code Snippets" feature, accessible via View > Utilities > Code Snippet Library. To add a new code snippet, select some text in the editor view and drag it into the snippet library. You can either drag a snippet out and drop it in your code to use it, or, much more conveniently, assign a completion shortcut to it.
When you type in that series of letters, it will automatically show up in the code completion pop-up menu as you type your code. For example, among many others, I have a snippet set up so that typing "svk" will expand to
setValue:<#value#> forKey:<#key#>
. This can save a lot of typing and/or fishing around in the autocompletion menu for the methods and other code expressions you use the most. Xcode ships with a bunch of built-in snippets that come in very handy as well.我最常使用的新快捷方式:三指滑动(向上或向下)以交换对应项(在接口和实现文件之间)。不再有手部杂技了!
感谢 https://twitter.com/xctotd/status/48148271759241216
New shortcut I use most often: triple-finger swipe (up or down) to swap counterparts (between the interface and implementation files). No more hand acrobatics!
Thanks to https://twitter.com/xctotd/status/48148271759241216
Xcode 4 中的选项卡非常棒。每个选项卡都维护自己独立的布局,因此您可以拥有多个选项卡,其中包含不同的内容,并且每个选项卡都可以适当地布局。
我一直在使用 三种布局设置我的项目 - 一种用于项目对象,一种用于每个笔尖(显示所有者类的源代码),每个班级一个。
这里有一个错误:从 4.0 开始,当您重新打开项目时,Xcode 将重置活动选项卡的状态(关闭任何助手)。解决方法是在关闭项目之前切换到没有 Xcode 助手的选项卡来关闭。我已将其归档为雷达号 9178441。
Tabs in Xcode 4 are awesome. Each one maintains its own separate layout, so you can have multiple tabs with different things in them and have each one lain out appropriately.
I've been setting up my projects with three layouts—one for the project object, one for each nib (showing the owner's class's sources), and one for each class.
There is one bug here: As of 4.0, Xcode will reset the state (turning off any Assistants) of the active tab when you reopen the project. The workaround is to switch to a tab with no Assistants for Xcode to close before you close the project. I have filed this as Radar number 9178441.
shift-选项 - 单击
组和文件列表项目导航器中的文件,或按住shift-<从跳转栏中选择文件时的kbd>选项。你会得到一个流行音乐-从中选择打开文件的位置。 新的或现有的选项卡、新的或现有的拆分(助理)编辑器、新窗口 - 每个可能的选项都在那里。
shift-option-click on a file in the
Groups and Files listProject Navigator, or hold shift-option while choosing a file from the Jump Bar.You'll get a pop-over from which to pick where to open the file. New or existing tab, new or existing split (Assistant) editor, new window—every possible option is there.
ctrl-6 弹出跳转栏的文件内段(启用键盘控制的跳转到方法)
cmd-{/} 选择上一个/下一个选项卡
< kbd>cmd-J 导航到任何编辑器(但是为什么哦为什么不在它们之间循环使用 TAB?)
ctrl-6 pops down within-file segment of jump bar (enables keyboard-controlled jump to methods)
cmd-{/} select previous / next tab
cmd-J navigate to any editor (but why oh why doesn't TAB then cycle between them?)
编辑器快捷键
.h& .m 文件。
已编辑的文件/下一个已编辑的文件。
布局快捷键
导航器快捷键
选项卡切换&跳跃
检查器
构建相关
代码折叠
Editor ShortCuts
.h & .m Files.
Edited Files/Next Edited files.
Layout Shortcuts
Navigators Shortcuts
Tab Switching & Jumping
Inspectors
Build Related
Code Folding
这是第一个。标签! Xcode 4 用持久选项卡取代了 Xcode 3 有用但很少使用的“收藏夹栏”。这意味着您可以在选项卡栏中保留一组常用文档的工作集。
不完全是一个隐藏的功能 - 但选项卡是持久的这一事实可能很容易被忽视。
Here's the first. Tabs! Xcode 4 has replaced Xcode 3's useful but rarely used "favorites bar" with persistent tabs. This means you can keep a working set of commonly used documents in your tab bar.
Not exactly a hidden feature as such - but the fact that the tabs are persistent is perhaps easily missed.
如果您在项目索引方面遇到任何问题(例如,自动完成中未显示符号),请打开“管理器”窗口,单击“项目”选项卡,然后使用“删除”按钮删除项目的派生数据。这将强制重建项目的索引,并丢弃任何构建的产品。
If you're having any sort of trouble with the indexing of your project (e.g. symbols not showing up in autocompletion), open the Organizer window, click the Projects tab, and use the "Delete" button to delete the derived data for your project. This will force a rebuild of the project's index, as well as tossing out any built products.
在较小屏幕上工作的一些有用的热键是:
cmd-shift-y - 隐藏和显示控制台/调试区域
cmd-< kbd>0 - 隐藏和显示文件导航
Some useful hotkeys for working on smaller screens are:
cmd-shift-y - Hide and show the console/debug area
cmd-0 - Hide and show the file navigation
您现在可以将项目导航器中的组与磁盘上的文件夹相关联。之前一直困扰我的是,Xcode 3 文件视图可能无法代表磁盘上项目的实际结构。
创建一个新组,然后突出显示新组,打开文件检查器。在右侧的身份部分,“路径”正下方是一个小图标,单击此图标可打开文件浏览器对话框,允许您选择该组的目录。
You can now associate groups in the Project Navigator with folders on disk. It always bugged me before that the Xcode 3 file view may not represent the actual structure of the project on disk.
Create a new group, then with the new group highlighted, open the File Inspector. In the identity section on the right just below the 'Path' is a small icon, click this to open the file browser dialog allowing you to select the directory for this group.
如果按住 FN 键,则可以使用光标键扫描文档,而无需移动光标
If you hold the FN key then you can scan through your document with the cursorkeys, without moving the cursor
跳转栏:
如果你写外部函数:
会喜欢:
您也可以搜索:
使用 Option 单击(同时按下 Shift,您可以选择另一个窗口),您可以看到一个对话框,让您指定文件应打开的位置:
源代码控制:
如果您使用 svn 或 git,放弃更改很容易:
界面生成器
在 xcode 4.2 中,您可以在此处跳转到界面生成器:
使用 Shift 单击 ui 对象,将显示其下所有对象的列表重点。
试试这个:
选择一个 ui 对象,按住 Option,然后将鼠标移到其他对象上。它会喜欢:
其他
热键:Shift+Command+O 快速打开
尝试:
并阅读:
编写和编辑源代码
Jump bar:
if your write outside function:
Will like:
Also you can search:
Click with Option(With Shift at the same time, you can choice another window), you can see a dialog letting you specify where the file should open:
Source control:
If you use svn or git, discard change is easy:
Interface buidler
In xcode 4.2, you can jump to interface builder here:
Click a ui object with Shift, it will show a list of all objects under the point.
Try this:
Select a ui object, hold Option, then move mouse over other objects. It will like:
Other
Hotkey: Shift+Command+O Open Quickly
Try:
And read:
Writing and Editing Source Code
文本编辑器:
添加框架:您不能简单地通过右键单击项目或组(如 Xcode 3 中)来完成此操作。您需要转到项目视图,选择目标并转到“构建阶段”选项卡。可以在“将二进制文件与库链接”部分下管理框架。
设置目标依赖项:与上面类似,在“构建阶段”选项卡的“目标依赖项”部分中。
确保您的档案安全 - 在安装 Xcode 4(从 3 开始)之前。您将失去它们(很可能),并因此失去象征崩溃日志的能力。
删除操作 - 请注意:“删除”(而不是“仅删除参考”)会直接从驱动器中删除文件。它不会进入垃圾箱,因此您无法恢复它。
Text Editor:
Adding frameworks: You cannot simply do this by right-clicking on the project or a group (like in Xcode 3). You need to go to the project view, select your target and go to "Build Phases" tab. Frameworks can be managed under the "Link Binary with Libraries" section.
Setting target dependencies: Similar to the above, in the "Target Dependencies" section of the "Build Phases" tab.
Keep your archives safe -prior to installing Xcode 4 (from 3). You will lose them (most likely) and with them lose your ability to symbolicate your crash logs.
Delete action-BEWARE: "Delete" (instead of "Remove Reference Only") directly erases the file from your drive. It doesn't go into the Trash, so you cannot recover it.
cmd-J 跳转到编辑器,但如果您打开了多个编辑器,您会得到一个包含所有打开的编辑器的覆盖层。您可以使用 cmd-→ 和 cmd-← 在打开的编辑器之间切换。
另外,如果您很难找到任何选项或属性,实用程序窗口可能是您最好的选择:
隐藏和显示实用程序:
cmd-opt -0这里通常隐藏一些不直观的东西:
cmd-J jumps to the editor, but if you have more than one editor open you get an overlay that has all of the open editors. you can use cmd-→ and cmd-← to switch between the open editors.
Also, if you are having a hard time finding an option or property for anything the utilites window is probably your best bet:
hide and show utilities:
cmd-opt-0Things that are commonly hidden here that aren't intuitive:
示例:
例子:
Example:
Example:
我最喜欢的功能之一是“打开选项卡”行为偏好。如果您转到“首选项”中的“行为”,则可以将其设置为在运行开始时转到特定选项卡。您可以为该选项卡命名,例如“调试”,如果它不存在,Xcode4 将为您创建它,并在您开始调试时将您带到那里。您可以按照自己喜欢的方式配置此选项卡以进行调试会话,并且在关闭它后它将保持这种状态,因此每当您运行 Xcode4 时,都会在单独的选项卡中按照您想要的方式进行设置。您甚至可以将此选项卡撕成一个单独的窗口,在这种情况下,Xcode4 将在您每次开始运行时打开一个新的专门配置的“调试”窗口!此功能非常有用,因为它使您的常规代码编辑选项卡或窗口与日志和调试器窗格保持整洁。运行完成后,只需关闭“调试”窗口,即可返回干净的代码屏幕。
One of my favorites is the "Open Tab" behavior preference. If you go to "Behaviors" in Preferences, you can set it to go to a specific tab whenever a run starts. You can name the tab, something like "Debug" and Xcode4 will create it for you if it doesn't exist, and take you there when you start debugging. You can configure this tab just how you like it for debugging sessions, and it will stick that way after you close it, so whenever you do a run Xcode4 will be set up just how you want it, in a separate tab. You can even tear this tab off to a separate window, in which case Xcode4 will open a new specially configured "Debug" window each time you start a run! This feature is great because it keeps your regular code editing tab or window uncluttered with the log and debugger panes. Simply close the "Debug" window when you're done running and you can be back to your clean screen of code.
在 XCode3 中,有一个“重命名项目”的选项。现在,您只需单击两次(第二次缓慢单击)即可重命名项目和名称。完成了。
In XCode3, There was an option for "Rename the Project". Now, you just need to click twice ( second click slowly ) to rename the project & Its done.
限制并发构建操作的数量
这是一个(某种程度上)隐藏的首选项,允许您定义并发编译任务的数量:
在 IDE 中禁用索引
这个禁用代码感知索引,这可以在大型项目中节省大量资源:
重新启用:
请注意,您应该退出 Xcode,根据需要设置首选项值,更改在重新启动 Xcode 时生效。
To Limit the Number of Concurrent Build Operations
This is a (somewhat) hidden preference which allows you to define the number of concurrent compile tasks:
To Disable Indexing in the IDE
This one disables code sense indexing, which can save a lot of resources in large projects:
to reenable:
Note that you should quit Xcode, set the preference values as desired, changes take effect when you restart Xcode.
如果您更喜欢使用在终端或任何其他外部编辑器上运行的 vim/emacs,您可以创建您的 Xcode 项目,添加文件等,然后切换到使用最适合您的编辑方式编辑所述文件;每当您将焦点切换到 xcode4 窗口时,修改后的文件将被重新加载(Xcode3 也是如此),您可以构建/运行您的应用程序。
If you prefer using vim/emacs running on, say, Terminal, or any other external editor, you can just create your xcode project, add files and whatnot and then switch to editing said files using whichever edit suits you best; whenever you switch focus to an xcode4 window, the modified files will be reloaded( was also the case with Xcode3 ) and you can build / run your application.
使用 XCode4 首选项的两种构建位置规范。
/Users/digicorp/ Library/Developer/XCode/DerivedData
)请查看以下屏幕截图。
Two kinds of Build location specification using XCode4 Preferences.
/Users/digicorp/Library/Developer/XCode/DerivedData
)Please look at following screen shots.
快速帮助
Ctrl + Option / Alt + f
查找快速帮助。例如,
我的文本光标位于
NSString
&如果我按 Ctrl + Option + f 那么它将在检查器/实用程序中显示快速文档。QUICK HELP
Ctrl + Option / Alt + f
Find the Quick help. For example,
My Text cursor is at
NSString
& if I press Ctrl + Option + f then It will show a quick documentation in the inspector/utilities.