有没有办法禁用或修改 Xcode 的代码完成?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2218713/
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-14 19:06:56  来源:igfitidea点击:

Is there a way to disable or modify Xcode's code completion?

xcodesettingscustomizationcode-completion

提问by e.James

I have unchecked both "Show arguments in pop-up list" and "Insert argument placeholders for completions" in Xcode Code Sense preferences, but when I type "else" (for example) in the editor, Xcode still dumps in a pre-formatted "else" block.

我在 Xcode Code Sense 首选项中取消选中了“在弹出列表中显示参数”和“插入参数占位符以完成补全”,但是当我在编辑器中键入“else”(例如)时,Xcode 仍然以预先格式化的格式转储“其他”块。

Is there a way to disable this feature entirely, or (better yet) to modify the block that Xcode inserts? The default Xcode "else" block doesn't match my coding style, so the placeholder actually hampers my productivity instead of helping.

有没有办法完全禁用此功能,或者(更好)修改 Xcode 插入的块?默认的 Xcode“else”块与我的编码风格不匹配,所以占位符实际上阻碍了我的工作效率而不是帮助。

UPDATE:I just found this questionWhich describes how to change the default indentation and whitespace used for code completion, so that answers the second half of my question.

更新:我刚刚发现这个问题,它描述了如何更改用于代码完成的默认缩进和空格,以便回答我问题的后半部分。

UPDATE #2:Setting "Automatically Suggest" to "never", as suggested by outiseffectively disables code completion entirely. I suppose what I'm looking for is a way to disable specificcode completions, (like the "else" block) while keeping all of the usual completions for variable and method names.

更新 #2:按照outis 的建议,将“自动建议”设置为“从不”可以有效地完全禁用代码完成。我想我正在寻找的是一种禁用特定代码完成(如“else”块)同时保留变量和方法名称的所有常用完成的方法。

采纳答案by Kendall Helmstetter Gelner

You can override any of the existing code completions, copy any of the .xtcmacro files from:

您可以覆盖任何现有的代码完成,从以下位置复制任何 .xtcmacro 文件:

/Applications/Xcode.app/Contents/PlugIns/TextMacros.xctxtmacro

(you'll have to right-click on Xcode.app and say "Show Package Contents" to proceed further down the directory chain unless you are using Terminal)

(除非您使用终端,否则您必须右键单击 Xcode.app 并说“显示包内容”以进一步向下移动目录链)

into a local directory:

进入本地目录:

~/Library/Application Support/Developer/Shared/Xcode/Specifications

(You'll probably have to make the Specifications directory). Then simply go through all of the definitions in there, to eliminate an annoying completion you can take out the CompletionPrefixfor any entry, or edit the code to be inserted to work how you like.

(您可能必须创建 Specifications 目录)。然后只需浏览其中的所有定义,以消除烦人的完成,您可以删除CompletionPrefix任何条目,或编辑要插入的代码以按您喜欢的方式工作。

On a side note, you can put any file named .xctxtmacro and put it in that specifications directory and it will be read in, allowing you to define some very useful custom macros.

附带说明一下,您可以将任何名为 .xctxtmacro 的文件放入该规范目录中,它将被读入,从而允许您定义一些非常有用的自定义宏。

回答by outis

The "Text Editing" and "Indentation" preference sections might have the settings you seek.

“文本编辑”和“缩进”首选项部分可能具有您想要的设置。

You can set "Automatically suggest" to "never".

您可以将“自动建议”设置为“从不”。

回答by Jayprakash Dubey

You can enable/disable code completion in Xcodeusing below steps:

您可以使用以下步骤在 Xcode 中启用/禁用代码完成

  1. Click on Xcodemenu on top-left corner
  2. Select Preferences...(Preference Pop-up appears)
  1. 点击Xcode左上角的菜单
  2. 选择Preferences...(出现首选项弹出窗口)

Screenshot-1 for steps

步骤截图 1

  1. Select Text Editingmenu
  2. See Code Completion.
  3. Uncheck Suggest completion while typingoption.
  1. 选择Text Editing菜单
  2. Code Completion
  3. 取消选中Suggest completion while typing选项。

Screenshot-2 for steps

步骤截图 2