如何使Xcode在Swift的新行中放置起首括号? [英] How to make Xcode put starting brace on new line in Swift?

查看:126
本文介绍了如何使Xcode在Swift的新行中放置起首括号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经注意到,Swift中的编码风格似乎是将花括号与方法签名或if语句等放在同一行.在不争论是非的情况下,我的目的只是为了获得Xcode.在完成自动补全和新文件模板时将花括号放在新行上.

I have noticed that the coding style in Swift appears to be to put braces on the same line as a method signature or if statement etc. Without getting into a debate about which is right or wrong, my aim is simply tom get Xcode to put the braces on a new line when it does its auto completion and for the new file templates.

我在这里尝试过建议,但它不起作用: https://forums. developer.apple.com/thread/23087

I've tried the advice here and it doesn't work: https://forums.developer.apple.com/thread/23087

我正在Sierra上使用Xcode 8.1.

I'm using Xcode 8.1 on Sierra.

还有其他人能够使它正常工作吗?

Has anyone else been able to get this to work?

谢谢, 艾伦

推荐答案

您可以结合使用以下方法来完成此任务.

You can use below methods in conjunction to accomplish this task.

ClangFormat

ClangFormat and Uncrustify

上述方法只会更改默认的语句模板,而不会更改内置方法的格式. (即自动填充的viewDidLoad()方法在同一行中仍具有大括号.)为此,您应该考虑使用这些插件.他们可以选择以指定格式保存文件.

Above method will only change the default statement templates and not the inbuilt methods formatting. (i.e autofilled viewDidLoad() method will still have the braces in the same line.) For this you should consider using these plugins. They have options to save the file with specified format.

(更新代码段编辑不再起作用)

(UPDATE Snippet Edit no longer works)

代码段编辑

Snippet Edit

代码段编辑是一个小程序,用于编辑Xcode的标准代码段.我们必须这样做,因为没有直接的方法可以在Xcode设置中更改代码样式,并且自Xcode 4起不支持XCCodeSenseFormattingOptions

Snippet Edit is a small program that is used to edit the Xcode's standard code snippets. We have to do this way because there is no direct way to change the code style in Xcode settings and XCCodeSenseFormattingOptions is not supported since Xcode 4

您可以按照以下屏幕截图进行参考.完成编辑后,请记住重新启动Xcode.

You can follow below screenshot for reference. Remember to restart Xcode once you are done with editing.

这篇关于如何使Xcode在Swift的新行中放置起首括号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆