xcode编码

    科技2026-09-21  20

    xcode编码

    开发人员生产力(Developer Productivity)

    As developers, we spend a considerable amount of time in our IDE, so it’s worth becoming an expert in using it. Simply being able to edit code doesn’t cut it — you need to become proficient.

    作为开发人员,我们在IDE中花费了大量时间,因此值得成为使用它的专家。 仅仅能够编辑代码并不能减少代码-您需要精通。

    In The Pragmatic Programmer, the authors recommend choosing one editor, and using it for all editing tasks. The reasoning behind their recommendation is simple: once you’ve memorised all keyboard shortcuts, your productivity will soar.

    在The Pragmatic Programmer中,作者建议选择一个编辑器,并将其用于所有编辑任务。 他们提出建议的理由很简单:记住了所有键盘快捷键后,您的工作效率就会大大提高。

    While you could certainly use an editor like VS Code to edit your source code, as iOS / macOS / watchOS / tvOS developers, we’re somewhat bound to use Xcode, as it includes a lot more tools than just the source code editor.

    尽管您可以肯定地使用VS Code这样的编辑器来编辑源代码,但作为iOS / macOS / watchOS / tvOS开发人员,我们一定会使用Xcode,因为它不仅包含源代码编辑器,还包含更多工具。

    Nevertheless, it pays off to know your way around Xcode and be proficient in the core editing and navigation commands to increase your productivity.

    尽管如此,了解Xcode的方式并精通核心编辑和导航命令以提高工作效率还是值得的。

    I’ve collected a list of my favourite keybindings and mouse commands — hope you’ll find them useful as well! All keybindings listed here use Xcode’s default keybinding — with one notable exception.

    我已经收集了我最喜欢的键盘和鼠标命令的列表-希望您也能找到它们的用处! 此处列出的所有键绑定均使用Xcode的默认键绑定-一个值得注意的例外。

    ⌘ = Command

    ⌘=命令 ⌥ = Option/Alt

    ⌥=选项/替代⇧ = Shift

    ⇧=移位⌃ = Control

    ⌃ =控制←→ ↑↓ = Arrow keys

    ←→↑↓=方向键↩ = Enter

    ↩=输入

    编辑中(Editing)

    Let’s begin with editing — this is one of the most basic activities, so every little improvement will boost your productivity!

    让我们从编辑开始-这是最基本的活动之一,因此每一个小的改进都会提高您的生产力!

    代码完成(⌃ +空格) (Code Completion (⌃ + Space))

    It’s hard to imagine working without code completion — I use it all of the time to explore APIs, and to save time when typing.

    很难想象没有代码完成就可以工作-我一直都在使用它来探索API,并节省了键入时的时间。

    移动线(⌥+⌘+ [和⌥+⌘+]) (Moving Lines (⌥ + ⌘ + [ and ⌥ + ⌘ + ]))

    Moving single lines or entire blocks around in your code is immensely useful, for example when organising code that belongs together. Xcode automatically takes care of indentation \o/

    在代码中四处移动单行或整个块非常有用,例如,在组织属于一起的代码时。 Xcode自动处理缩进\ o /

    删除整行(⌘+ D) (Delete Entire Line (⌘ + D))

    I often need to delete an entire line — Xcode offers an editor command for this, but unfortunately it is not bound to a key combo in the default key bindings. After some consideration I decided to make an exception and include a custom key combo in this list, just because I think it is so useful. To define custom keybindings, go to Xcode settings (press ⌘ + ,), navigate to the Key Bindings tab, and use the filter field to search for “Delete Line”. Double click into the Key field, then press your preferred key combo.

    我经常需要删除整行-Xcode为此提供了一个编辑器命令,但是不幸的是,它没有在默认键绑定中绑定到键组合。 经过一番考虑,我决定做一个例外,并在列表中加入一个自定义键组合,只是因为我认为它非常有用。 要定义自定义按键绑定,请转到Xcode设置(按⌘+,),导航到“按键绑定”选项卡,然后使用过滤器字段搜索“删除行”。 双击进入“密钥”字段,然后按您的首选组合键。

    评论当前行/块(⌘+ /) (Comment Current Line / Block (⌘ + /))

    Useful for temporarily deactivating a bunch of lines in your code. But please remember to not check this in. Your version control system is a better tool for going back in history than a chunk of commented lines!

    对于暂时停用代码中的几行很有用。 但是请记住不要签入。版本控制系统比起很多注释行,是回顾历史的更好工具!

    余额缩进(⌃ + I) (Balance Indentation (⌃ + I))

    Just like many of the other commands above, this works both on single lines and on entire blocks of code. Useful after pasting code from elsewhere (did somebody say Stack Overflow?).

    就像上面的许多其他命令一样,它既可以在一行上运行,也可以在整个代码块上运行。 在从其他位置粘贴代码后很有用(有人说堆栈溢出吗?)。

    导航 (Navigation)

    Estimates say that you read a lot more code than you will write, and I wholeheartedly agree. You read code all of the time: when digging into a new codebase, when debugging, and even when writing new code! Here are a couple of commands that will help you stay on top of your navigation.

    据估计,您阅读的代码比编写的要多得多,我完全同意。 您一直在阅读代码:挖掘新代码库,调试甚至编写新代码! 这里有一些命令,可以帮助您掌握导航的顶部。

    来回走动(⌃ +⌘+←和⌃ +⌘+→) (Going Back and Forth (⌃ + ⌘ + ← and ⌃ + ⌘ + →))

    Xcode tracks your entire movement history as soon as you open or create a project. Any file you go to, any symbol you look up — it all is appended to the IDE’s navigation stack. Use ⌃ + ⌘ + ← and ⌃ + ⌘ + → to go back and forth between the source code locations you visited.

    一旦打开或创建项目,Xcode就会跟踪您的整个移动历史。 您要访问的任何文件,您查找的任何符号-所有这些都将附加到IDE的导航堆栈中。 使用⌃ +⌘+←和⌃ +⌘+→在您访问过的源代码位置之间来回移动。

    跳转到定义(⌃ +⌘+ J或⌃ +⌘+单击) (Jump to Definition (⌃ + ⌘ + J or ⌃ + ⌘ + Click))

    This comes in really handy when learning new APIs or navigating an unknown codebase. Not sure what ObservedObject does? Navigate to its definition to see which methods and properties it has, which interfaces it implements and which class it inherits from. For most of Apple’s APIs, you’ll also see the documentation (of course, you can always invoke Quick help using ⌥ + click)

    当学习新的API或浏览未知的代码库时,这非常方便。 不确定ObservedObject做什么? 导航至其定义,以查看其具有的方法和属性,实现的接口以及从中继承的类。 对于大多数Apple API,您还将看到文档(当然,您始终可以使用⌥+单击来调用快速帮助)

    在工作区中查找选定的符号(⇧+ ⌃ +⌘+ F) (Find Selected Symbol in Workspace (⇧ + ⌃ + ⌘ + F))

    This is essentially the opposite of Jump to Definition, and it’s particularly helpful when trying to understand how an API is used in the codebase. It also gives you a feeling for how much grief you’re going to cause your teammates (or other API consumers) when refactoring an API…!

    这本质上与“跳转到定义”相反,并且在试图了解如何在代码库中使用API​​时特别有用。 它也使您感觉到重构API时会给您的队友(或其他API使用者)带来多少痛苦……!

    查找呼叫层次结构(⇧+ ⌃ +⌘+ H) (Find Call Hierarchy (⇧ + ⌃ + ⌘ + H))

    Similar to Find selected symbol in workspace, but with a focus on methods, this shortcut will open the Call Hierarchy view to show any places in your code that call the specified method, as well as any methods that call those methods in turn, and so on.

    与在工作区中查找选定的符号类似,但着重于方法,此快捷方式将打开“调用层次结构”视图,以显示代码中调用指定方法的任何位置,以及依次调用这些方法的所有方法,等等。上。

    快速打开(⇧+⌘+ O) (Open Quickly (⇧ + ⌘ + O))

    If you take away only one thing from reading this article, make it this one. Open quickly allows you to quickly jump into any source location in your project / workspace. Just start typing the name of any class, interface, function, method, enum, … in your project (and any SDK you imported) and it will populate the popup with a list of symbols that match the search term. It performs some fuzzy searching, so you can type partial search terms like UIAD to search for UIApplicationDelegate.

    如果您从阅读本文中仅拿走了一件事,那就做这件事。 快速打开允许您快速跳转到项目/工作区中的任何源位置。 只需在项目(以及您导入的任何SDK)中键入任何类,接口,函数,方法,枚举,…的名称,它将在弹出窗口中填充与搜索词匹配的符号列表。 它执行一些模糊搜索,因此您可以键入UIAD类的部分搜索项来搜索UIApplicationDelegate 。

    跳到线(⌘+ L) (Jump to Line (⌘ + L))

    Useful for when, you know, you need to navigate to a specific line in the current file.

    在您需要导航到当前文件中的特定行时很有用。

    文档大纲(⌃ + 6或⌘+悬停小地图) (Document Outline (⌃ + 6 or ⌘ + hovering the minimap))

    These actually are two different pieces of UI, but they basically do the same:

    这些实际上是用户界面的两个不同部分,但它们基本上是相同的:

    Use ⌃ + 6 to drop down a menu from the Jump Bar (the area directly above the code editor) with all the symbols in the current source file. You can then navigate using the arrow keys, or by starting to type to filter the list of symbols. Useful not just for large files.

    使用⌃ + 6从跳转栏(位于代码编辑器正上方的区域)下拉菜单,其中包含当前源文件中的所有符号。 然后,您可以使用箭头键导航,或者通过开始键入以过滤符号列表来导航。 不仅对大文件有用。

    The minimap was a welcome addition to the Xcode editor in one of the recent releases of Xcode and provides a high-level visual overview of your code (Apple, if you’re reading this: can we please get a way to zoom the minimap, e.g. by dragging the divider?). When hovering over the minimap, it will display a flyout with the name of the symbol the mouse cursor is hovering over. Press ⌘ while hovering to see a list of all symbols.

    在最近发布的Xcode之一中,小地图是Xcode编辑器的一个受欢迎的补充,它为您的代码提供了高级的可视化概览(Apple,如果您正在阅读此书,我们是否可以获取一种缩放小地图的方法,例如,拖动分隔线?)。 将鼠标悬停在小地图上时,它将显示弹出窗口,并带有鼠标光标悬停在其上的符号的名称。 悬停时按to可查看所有符号的列表。

    查看管理 (View Management)

    Let switch gears and take a look at view management. The editor takes up most of the screen real estate in Xcode, and it is surrounded by a number of views that display contextual information.

    让我们切换一下齿轮,看看视图管理。 编辑器占用了Xcode的大部分屏幕资源,并且被许多显示上下文信息的视图所围绕。

    切换Canvas / SwiftUI预览(⌥+⌘+↩) (Toggle Canvas / SwiftUI Preview (⌥ + ⌘ + ↩))

    When writing SwiftUI code, Canvas provides a live preview of the UI you’re building. Apple has gone to great lengths to make this a two-way experience, i.e. any changes you make in the preview (e.g. by moving UI elements, or adding new ones) will be reflected in the code editor as well, and vice versa. This allows for rapid prototyping with fast turn-around times. You no longer need to launch your application to check if the button looks better in red or in blue.

    在编写SwiftUI代码时, Canvas提供了正在构建的UI的实时预览。 Apple竭尽全力使之成为一种双向体验,即您在预览中所做的任何更改(例如,通过移动UI元素或添加新元素)也将反映在代码编辑器中,反之亦然。 这样可以快速建立原型,并具有快速的周转时间。 您不再需要启动应用程序来检查按钮的红色还是蓝色外观更好。

    However, we don’t always need to see the preview, so it’s good to be able to toggle it as required. Use ⌥ + ⌘ + ↩ to hide or show the Canvas.

    但是,我们并不总是需要查看预览,因此最好能够根据需要进行切换。 使用⌥+⌘+↩隐藏或显示画布。

    切换视图 (Toggle Views)

    Xcode has three main areas surrounding the code editor, which can be toggled to make more space for editing (or showing context information, just as required):

    Xcode在代码编辑器周围有三个主要区域,可以切换它们以留出更多空间进行编辑(或根据需要显示上下文信息):

    Left: Navigator (⌘ + 0)

    左:导航器(⌘+ 0) Right: Inspectors (⌘ + ⌥ + 0)

    右:检查员(⌘+⌥+ 0) Bottom: Debug (⇧ + ⌘ + Y)

    底部:调试(⇧+⌘+ Y)

    概要 (Summary)

    And that was a quick tour of my favourite productivity shortcuts in Xcode 11. Here is a table to give you a quick overview of the commands and key bindings:

    然后快速浏览了我在Xcode 11中最喜欢的生产力快捷方式。下面的表格为您快速概述了命令和键绑定:

    演示地址

    What are your favourite shortcuts? Let me know in the comments or share with me on Twitter!

    您最喜欢的快捷方式是什么? 在评论中让我知道或在Twitter上与我分享!

    翻译自: https://medium.com/flawless-app-stories/essential-xcode-shortcuts-for-more-efficient-coding-1f8e58b2c907

    xcode编码

    相关资源:四史答题软件安装包exe
    Processed: 0.009, SQL: 10