DEV Community

Cover image for How to improve swift code using SwiftLint & Swiftformat
Japneet Singh
Japneet Singh

Posted on

How to improve swift code using SwiftLint & Swiftformat

Hello Everyone, Welcome to my blog on how to format swift code using swiftformat & swiftlint.

TOOLS USAGE

$ brew install swiftformat
$ swiftformat [fileName]
Enter fullscreen mode Exit fullscreen mode
$ brew install swiftlint
$ swiftLint [fileName]
Enter fullscreen mode Exit fullscreen mode

INTEGRATE XCODE

Integrate SwiftLint into your Xcode project to get warnings and errors displayed in the issue navigator.
To do this click the Project in the file navigator, then click the primary app target, and go to Build Phases. Click the + and select "New Run Script Phase". Insert the following as the script:
Image description

Similarly, create the build phase with Swiftformat.

ISSUES RELATED TO SOURCE CODE

Issues found during the lint format:
Image description

Tool to run from command line

$ swift run ModernSSG | swiftformat .
Enter fullscreen mode Exit fullscreen mode

Other IDE Integrations

  1. AppCode

To integrate SwiftLint with AppCode, install
this plugin and configure
SwiftLint's installed path in the plugin's preferences.
The autocorrect action is available via βŒ₯⏎.

2.Atom

To integrate SwiftLint with Atom, install the
linter-swiftlint package from
APM.

  1. Visual Studio Code

To integrate SwiftLint with vscode, install the
vscode-swiftlint extension from the marketplace.

Conclusion

This source code format in swift is easy and prominent for the development process and makes code less prone to small errors. This development will surely reduce the issues and make a constant format for new projects.

Commits

merged_commit

Top comments (1)

Collapse
 
shappy007 profile image
Gurpreet Grewal

Thanks a lot bro β˜ΊοΈπŸ™