objective-c Xcode 的隐藏功能

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/146297/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 20:46:55  来源:igfitidea点击:

Hidden Features of Xcode

objective-cxcodemacoscocoa

提问by schwa

With a huge influx of newbies to Xcode, I'm sure there are lots of Xcode tips and tricks to be shared.

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

What are yours?

你的是什么?

回答by epatel

Switch to Header/Source File

切换到头文件/源文件

  • Option ?Command ?Up Arrow ↑

  • View> Switch to Header/Source File

  • Option ?Command ?Up Arrow ↑

  • 查看>切换到头文件/源文件

Switches between the .mand .hfiles.

.m.h文件之间切换。

  • In Xcode 4 this is ctrlCommand ?Up Arrow ↑
  • 在 Xcode 4 中,这是 ctrlCommand ?Up Arrow ↑

回答by schwa

? Command+ Double-Click on a symbol: Jump to Definition of a symbol.

? Command+ Double-Click on a symbol: 跳转到符号的定义。

? Option+ Double-Click on a symbol: Find Text in Documentation of a symbol. (Only works if you have they symbol's Doc Set installed.)

? Option+ Double-Click on a symbol:在符号的文档中查找文本。(仅当您安装了他们符号的文档集时才有效。)

Favorites Bar:

收藏栏:

Favorites bar is just like you have in Safari for storing - well - favorites. I often use it as a place to store shortcuts (which you can do by drag-dropping) to files I am using right now. Generally this is more useful when I'm working with a large or unfamiliar project.

收藏夹栏就像您在 Safari 中用于存储收藏夹一样。我经常用它来存储我现在正在使用的文件的快捷方式(您可以通过拖放来完成)。通常,当我处理大型或不熟悉的项目时,这更有用。

To show the Favorites Bar, select the following menu option:

要显示收藏夹栏,请选择以下菜单选项:

  • View> Layout> Show Favorites Bar
  • View> Layout>Show Favorites Bar

回答by mmalc

Auto-completion Keyboard Shortcuts

自动完成键盘快捷键

Tab ?OR Control ?/: Select the next auto-completion argument.

Tab ?Control ?/:选择下一个自动完成参数。

Shift ?Tab ?OR Shift ?Control ?/: Select the previous auto-completion argument.

Shift ?Tab ?Shift ?Control ?/:选择上一个自动完成参数。

Escape ?: Shows the auto completion pop-up list.

Escape ?:显示自动完成弹出列表。

回答by nevan king

Turn off the "undo past the last point" warning

关闭“撤消超过最后一点”警告

When you attempt to undo after saving, you will get the following prompt:

当您在保存后尝试撤消时,您将收到以下提示:

"You are about to undo past the last point this file was saved. Do you want to do this?"

“您将要在保存此文件的最后一点之后撤消。您要这样做吗?”

To get rid of this warning, enter the following into a terminal window:

要消除此警告,请在终端窗口中输入以下内容:

defaults write com.apple.Xcode XCShowUndoPastSaveWarning NO


Change the company name in template files

更改模板文件中的公司名称

Paste this into the Terminal application:

将其粘贴到终端应用程序中:

defaults write com.apple.Xcode PBXCustomTemplateMacroDefinitions '{"ORGANIZATIONNAME" = "Microsoft";}'


Change "com.yourcompanyname" in all your templates:

com.yourcompanyname在所有模板中更改“ ”:

  1. Find the directory: /Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Project Templates/Application
  2. Use your favourite multi-file search-and-replace tool to change com.yourcompanyto whatever value you normally use to build for a device. I used BBEdit's multi-find-and-replace after I opened the whole directory. You should be replacing the value in all the info.plistfiles. I found 8 files to change. The number of times a build has failed because I forgot to change this string is ridiculous.
  1. 找到目录: /Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Project Templates/Application
  2. 使用您最喜欢的多文件搜索和替换工具更改com.yourcompany为您通常用于为设备构建的任何值。打开整个目录后,我使用了BBEdit的多查找和替换。您应该替换所有info.plist文件中的值。我找到了 8 个要更改的文件。由于我忘记更改此字符串而导致构建失败的次数是荒谬的。


Quickly jump to a Group in the Groups and Files pane

快速跳转到组和文件窗格中的组

  • Control ?Option ?Shift ?+ <First letter of a Group name>
  • Control ?Option ?Shift ?+ <组名的首字母>

If you hold down the three keys above, you can quickly jump to groups in the left (Groups and Files) page by pressing the first letter of a groups name. For example, Control ?Option ?Shift ?Ttakes you to Targetsand Control ?Option ?Shift ?Sto Source. Press it again and it jumps to SCM. Sometimes it takes several tries for this to work (I don't know why).

按住上面三个键,可以通过按组名的第一个字母快速跳转到左侧(组和文件)页面中的组。例如,Control ?Option ?Shift ?T把你带到目标Control ?Option ?Shift ?S。再次按下它,它会跳转到 SCM。有时需要多次尝试才能工作(我不知道为什么)。



Cycling between autocompletion choices

在自动完成选项之间循环

  • Control ?.

  • Shift ?Control ?.: Cycles backwards between autocompletion choices.

  • Control ?.

  • Shift ?Control ?.:在自动完成选项之间向后循环。

Control ?.(Control-Period) after a word automatically accepts the first choice from the autocompletion menu. Try typing logthen Control ?.and you'll get a nice NSLogstatement. Press it again to cycle through any choices. To see all the mutable choices, type NSMuthen Control ?..

Control ?.(Control-Period) 一个词后自动接受自动完成菜单中的第一个选择。log然后尝试输入Control ?.,你会得到一个很好的NSLog陈述。再次按下可循环选择任何选项。要查看所有可变选项,请输入NSMuthen Control ?.



Quick Help

快速帮助

  • Control ?Command ??(While your cursor is in the symbol to look up)

  • Option ?+ <Double-click a symbol>

  • Help > Quick Help

  • Control ?Command ??(当您的光标在要查找的符号中时)

  • Option ?+ <双击符号>

  • 帮助 > 快速帮助

To get to the documentation from the Quick Help window, click the book icon on the top right.

要从“快速帮助”窗口访问文档,请单击右上角的书本图标。



See the documentation for a symbol

查看符号的文档

  • Command ?Option ?+ <Double-click a symbol>
  • Command ?Option ?+ <双击符号>

Takes you straight to the full documentation.

将您直接带到完整的文档。



Make non-adjacent text selections

选择不相邻的文本

  • Command ?Control ?+ <Double-click in the editor>
  • Command ?Control ?+ <在编辑器中双击>

Use the above shortcut for a strange way of selecting multiple words. You can make selections of words in totally different places, then delete or copy them all at once. Not sure if this is useful. It's Xcode only as far as I can tell.

使用上面的快捷方式以一种奇怪的方式选择多个单词。您可以在完全不同的地方选择单词,然后一次性删除或复制它们。不确定这是否有用。据我所知,它只是 Xcode。



Use Emacs key bindings to navigate through your code

使用 Emacs 键绑定来浏览您的代码

This trick works in all Cocoa application on the Mac (TextEdit, Mail, etc.) and is possibly one of the most useful things to know.

这个技巧适用于 Mac 上的所有 Cocoa 应用程序(TextEdit、Mail 等),并且可能是最有用的知识之一。

  • Command ?Left Arrowor Command ?Right ArrowTakes you to the beginning and end of a line.
  • Control ^aand Control ^eDo the same thing
  • Control ^nand Control ^pMove the cursor up or down one line.
  • Control ^fand Control ^bMove the cursor back or forward one space
  • Command ?Left Arrow或 带Command ?Right Arrow您到一行的开头和结尾。
  • Control ^aControl ^e做同样的事情
  • Control ^nControl ^p将光标向上或向下移动一行。
  • Control ^f并将Control ^b光标向后或向前移动一格

Pressing Shift ?with any of these selects the text between move points. Put the cursor in the middle of a line and press Shift ?Control ^eand you can select to the end of the line.

Shift ?其中任何一个键可选择移动点之间的文本。将光标放在一行的中间并按Shift ?Control ^e,您可以选择到该行的末尾。

Pressing Option ?will let you navigate words with the keyboard. Option ?Control ^fskips to the end of the current word. Option ?Control ^bskips to the beginning of the current word. You can also use Option ?with the left and right arrow keys to move one-word-at-a-time.

按下Option ?将让您使用键盘导航单词。Option ?Control ^f跳到当前单词的末尾。Option ?Control ^b跳到当前单词的开头。您还可以使用Option ?左右箭头键一次移动一个单词。

  • Control ^Left Arrowand Control ^Right Arrowmoves the cursor between camel-cased parts of a word.
  • Control ^Left ArrowControl ^Right Arrow在单词的驼峰式部分之间移动光标。

Try it with NSMutableArray. You can quickly change it to NSArrayby putting your cursor after the NS, pressing Shift ?Control ^Right Arrowthen Delete.

试试吧NSMutableArray。您可以NSArray通过将光标放在 之后NSShift ?Control ^Right Arrow然后按来快速将其更改为Delete

回答by Evan DiBiase

Open Quickly...

快速打开...

  • Command ?Shift ?D

  • File> Open Quickly...

  • Command ?Shift ?D

  • 文件>快速打开...

I'm a big fan of the Open Quicklyfeature, which is particularly good in Xcode 3.1 and later. When you want to open a file or a symbol definition that's in your project or in a framework, just hit the keyboard shortcut, type a bit of the file or symbol's name, use Up Arrow ↑and Down Arrow ↓to pick to the right result (if need be), and then hit Return ?to open the file or navigate to the symbol definition.

我非常喜欢Open Quickly功能,该功能在 Xcode 3.1 及更高版本中尤为出色。当您想打开项目或框架中的文件或符号定义时,只需点击键盘快捷键,键入一些文件或符号的名称,使用Up Arrow ↑Down Arrow ↓选择正确的结果(如果需要),然后点击Return ?打开文件或导航到符号定义。

On Xcode 4:

在 Xcode 4 上:

  • Command ?Shift ?o
  • Command ?Shift ?o


Open Quickly uses the current word as a search term

快速打开使用当前词作为搜索词

Also, something I didn't know about Xcode until two minutes ago (when schwapointed it out in a comment) is that, if the editor's text caret is inside of a word when Open Quicklyis invoked, that word will be used as the Open Quicklysearch term.

另外,直到两分钟前(当schwa在评论中指出时)我才知道 Xcode 的一些事情是,如果在调用Open Quickly时编辑器的文本插入符号在一个单词内,则该单词将用作打开快速搜索词。

回答by Steve Streza

Use #pragma for organization

使用 #pragma 进行组织

You can use:

您可以使用:

#pragma mark Foo

... as a way to organize methods in your source files. When browsing symbols via the pop up menu, whatever you place in Foowill appear bold in the list.

... 作为在源文件中组织方法的一种方式。通过弹出菜单浏览符号时,您放置的任何内容Foo都会在列表中显示为粗体。

To display a separator (i.e. horizontal line), use:

要显示分隔符(即水平线),请使用:

#pragma mark -

It's very useful, especially for grouping together delegate methods or other groups of methods.

它非常有用,特别是用于将委托方法或其他方法组组合在一起。

回答by Jon Hess

1. Breakpoint on "objc_exception_throw"

1. “objc_exception_throw”上的断点

You should always have a breakpoint on objc_exception_throw.

您应该始终在 上设置断点objc_exception_throw

2. Debugging retain/release problems with "Zombie" variables

2、调试“僵尸”变量的retain/release问题

Use the following code:

使用以下代码:

NSZombieEnabled = YES;
NSDeallocateZombies = NO;

... to debug retain and release problems. For more information, see the "Finding Memory Leaks" section of Apple's Debugging Applications document.

...调试保留和释放问题。有关更多信息,请参阅Apple 的调试应用程序文档的“查找内存泄漏”部分。

3. Jumping to a class in Xcode from Interface Builder

3.从Interface Builder跳转到Xcode中的一个类

Command ?+ Double-clickon an object in Interface Builder's Document Window to jump to that class in Xcode. This is very handy with File's Owner.

Command ?+Double-click在 Interface Builder 的文档窗口中的对象上跳转到 Xcode 中的那个类。这对于File's Owner非常方便。

4. Reusing customized objects in Interface Builder

4. 在 Interface Builder 中重用自定义对象

Drag a customized object back to Interface Builder's Library for later reuse.

将自定义对象拖回 Interface Builder 的库以供以后重用。

5. Select overlapping items in Interface Builder

5.在Interface Builder中选择重叠的项目

Control ?Shift ?+ Clickon an object in Interface Builder to see a menu of all of the objects under the mouse.

Control ?Shift ?+Click在 Interface Builder 中的对象上查看鼠标下所有对象的菜单。

6. Interface Builder Gesture Guide

6. 界面生成器手势指南

Interface Builder Gesture Guide.

界面生成器手势指南

回答by mgorbach

Ctrl+ 2: Access the popup list of methods and symbols in the current file.

Ctrl+ 2: 访问当前文件中方法和符号的弹出列表。

This is super useful because with this shortcut you can navigate through a file entirely using the keyboard. When you get to the list, start typing characters and the list will type-select to the symbol you are looking for.

这非常有用,因为使用此快捷方式,您可以完全使用键盘浏览文件。当您到达列表时,开始输入字符,列表将输入选择您要查找的符号。

回答by mmalc

Zoom Editor In

放大编辑器

If your window displays both the detail and editor view, you can zoom the editor into expand the editor view to the full height of the window. (This is fairly easily found, but many seem to overlook it.)

如果您的窗口同时显示详细信息和编辑器视图,您可以放大编辑器以将编辑器视图扩展到窗口的整个高度。(这很容易找到,但许多人似乎忽略了它。)

You can do this by using one of the following methods:

您可以使用以下方法之一执行此操作:

  • Command ?Shift ?E

  • View> Zoom Editor In

  • Drag the splitter (between the editor window and the file list above it) upwards.

  • Command ?Shift ?E

  • 视图>放大编辑器

  • 向上拖动分隔符(在编辑器窗口与其上方的文件列表之间)。

回答by Hagelin

Get Colin Wheeler's Complete Xcode Keyboard Shortcut List(available as PDF or PNG). Print it and keep it somewhere visible (I've got it on the wall next to my screen).

获取Colin Wheeler 的完整 Xcode 键盘快捷键列表(PDF 或 PNG 格式)。打印它并将它放在可见的地方(我把它放在屏幕旁边的墙上)。

edit: Updated versions for Xcode 3.2

编辑: Xcode 3.2 的更新版本

edit 2: Updated versions for Xcode 4

编辑 2: Xcode 4 的更新版本