-1

Trying to follow best practices for Swift style. Both Airbnb and Google's guides say to limit the column width to 100 characters. In Xcode, I can set the page guide to be at column 100. Then I can manually scan each file to see if a line goes past that guide…. Isn't there a better way?

For example, suppose I inherit a project and want to quickly know which files have lines past a certain column width. And in those files, which lines those are. How can I do this?

Ideally, the solution will be in Xcode (vs Terminal), so I can efficiently jump to each problem line and fix it. (I'm fine fixing each line manually, as I'm still getting a handle on Google's extensive line-wrapping guidelines.)

Geoff Hom
  • 162
  • 1
  • 9
  • 1
    You can use [swiftlint](https://github.com/realm/SwiftLint), it can be used both from within Xcode as a run script and from the terminal. – Joakim Danielson Apr 23 '21 at 14:40

1 Answers1

1

A linter will tell you this and much more. Most good linters are highly configurable (exact column limit) and integrate with Xcode.

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • Thank you. I see that SwiftLint recommends installing via CocoaPods. The Swift Package Manager isn't even mentioned as an option. Why? Should I post that as a separate question? – Geoff Hom Apr 23 '21 at 17:44
  • I don't see how a package would help you here; you said you wanted something integrates with Xcode. – matt Apr 23 '21 at 19:22
  • I thought I could use SPM instead of CocoaPods to install SwiftLint. E.g., this SO question (https://stackoverflow.com/questions/57461737/how-to-integrate-swiftlint-with-an-ios-app-using-swift-package-manager). But the answer there indicates one can use Mint. – Geoff Hom Apr 23 '21 at 22:10
  • 1
    We are _way_ off-topic with regard to your original question. – matt Apr 23 '21 at 23:40
  • FYI, SwiftLint worked. To get that working, I first installed Mint, then used Mint to install SwiftLint. Then in Xcode, I added the Run Script Phase as described in the SwiftLint readme (https://github.com/realm/SwiftLint#xcode). Now after building, Xcode shows any SwiftLint warnings/errors, just like other warnings/errors. SwiftLint's default column limits are 120/200, so I'll have to configure that. – Geoff Hom Apr 24 '21 at 03:54