-1

I'm using the auto creation of Xcode and would like to have the function-braces in a new line. I know this question was asked years before, but there is no working solution for me. I already set an option in the preferences, but I think this doesn't work for the templates. Preferences

currently:

override func viewDidLoad(){
    super.viewDidLoad()
    // Do any additional setup after loading the view.
}

Should be like this:

override func viewDidLoad()
{
    super.viewDidLoad()
    // Do any additional setup after loading the view.
}

How to fix this?

Thanks in advance!

Lukas
  • 11
  • 1
  • "but I think this doesn't work for the templates" No, why would it? They are templates; what is in the template file is what is in it. It does not reformat just because of your editing preferences. – matt Feb 12 '20 at 17:54
  • Right. Thought there is perhaps an option to change them somehow automatically. – Lukas Feb 12 '20 at 18:07
  • If you want to change templates, consider: https://stackoverflow.com/questions/33720/change-templates-in-xcode. If you want to pursue formatters, see https://nshipster.com/swift-format/. – Rob Feb 12 '20 at 18:10
  • Needless to say, I’d think long and hard about using nonstandard conventions. If it’s your own code and never, for example, plan on sharing it with other developers or show your code to a future employer to show off your great code, then do what you want. Hey, I get it: Many of us come from other coding conventions and love them and can rationalize why they’re superior, but you’ll be well served to embrace modern standards. – Rob Feb 12 '20 at 18:40
  • 1
    @Rob Thanks for the two links, but you changed my mind with your second comment. It is probably the best to stay with this templates and get along with a new standard. Thanks! – Lukas Feb 13 '20 at 08:27
  • @Rob There is nothing wrong with wanting braces on a new line. It's actually way cleaner and does not confuse other developers at all. There also isn't anything "modern" about using braces on the same line. That is an OLD technique to reduce paper usage. – trilogy Mar 16 '21 at 15:20
  • @trilogy - It’s not about paper usage. Lol. It is the style that Apple uses in their [The Swift Programming Language](https://docs.swift.org/swift-book/LanguageGuide/Functions.html) and, as such, is the de facto style. – Rob Mar 16 '21 at 15:31
  • @Rob I get that they use it, but that's where that style originally came from. It's an ad populum fallacy. Lots of old people used it because lots of people needed to save paper... that it came into standard use. Braces on a new line allows you to group sets of code more visually and easier to group them when it's nested code. – trilogy Mar 16 '21 at 16:38

1 Answers1

0

perhaps you could use SwiftFormat to reformat your code by the rules you specify in config. this would have to be added to the Xcode build system as script in build phase.

ha100
  • 1,563
  • 1
  • 21
  • 28