![](EditorExtension/Application/Assets.xcassets/AppIcon.appiconset/icon_256x256.png)
[![PayPal](https://img.shields.io/badge/paypal-donate-blue.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=9ZGWNK5FEZFF6&source=url)
[![Build](https://github.com/nicklockwood/SwiftFormat/actions/workflows/build.yml/badge.svg)](https://github.com/nicklockwood/SwiftFormat/actions/workflows/build.yml)
[![Codecov](https://codecov.io/gh/nicklockwood/SwiftFormat/graphs/badge.svg)](https://codecov.io/gh/nicklockwood/SwiftFormat)
[![Swift 5.1](https://img.shields.io/badge/swift-5.1-red.svg?style=flat)](https://developer.apple.com/swift)
[![License](https://img.shields.io/badge/license-MIT-lightgrey.svg)](https://opensource.org/licenses/MIT)
[![Mastodon](https://img.shields.io/badge/mastodon-@nicklockwood@mastodon.social-636dff.svg)](https://mastodon.social/@nicklockwood)
Table of Contents
-----------------
- [What?](#what-is-this)
- [Why?](#why-would-i-want-to-do-that)
- [How?](#how-do-i-install-it)
- [Command-line tool](#command-line-tool)
- [Xcode source editor extension](#xcode-source-editor-extension)
- [Xcode build phase](#xcode-build-phase)
- [Swift Package Manager plugin](#swift-package-manager-plugin)
- [Via Applescript](#via-applescript)
- [VSCode plugin](#vscode-plugin)
- [Sublime Text plugin](#sublime-text-plugin)
- [Nova plugin](nova-plugin)
- [Git pre-commit hook](#git-pre-commit-hook)
- [GitHub Actions](#github-actions)
- [On CI using Danger](#on-ci-using-danger)
- [Bazel build](#bazel-build)
- [Docker](#docker)
- [Configuration](#configuration)
- [Options](#options)
- [Rules](#rules)
- [Swift version](#swift-version)
- [Config file](#config-file)
- [Globs](#globs)
- [Linting](#linting)
- [Error codes](#error-codes)
- [Cache](#cache)
- [File headers](#file-headers)
- [FAQ](#faq)
- [Known issues](#known-issues)
- [Tip Jar](#tip-jar)
- [Credits](#credits)
What is this?
----------------
SwiftFormat is a code library and command-line tool for reformatting Swift code on macOS, Linux or Windows.
SwiftFormat goes above and beyond what you might expect from a code formatter. In addition to adjusting white space it can insert or remove implicit `self`, remove redundant parentheses, and correct many other deviations from the standard Swift idioms.
Why would I want to do that?
-----------------------------
Many programmers have a preferred style for formatting their code, and others seem entirely blind to the existing formatting conventions of a project (to the enragement of their colleagues).
When collaborating on a project, it can be helpful to agree on a common coding style, but enforcing that manually is tedious and error-prone, and can lead to arguments if some participants take it more seriously than others.
Having a tool to automatically enforce a common style eliminates those issues, and lets you focus on the behavior of the code, not its presentation.
How do I install it?
---------------------
That depends - There are several ways you can use SwiftFormat:
1. As a command-line tool that you run manually, or as part of some other toolchain
2. As a Source Editor Extension that you can invoke via the Editor > SwiftFormat menu within Xcode
3. As a build phase in your Xcode project, so that it runs every time you press Cmd-R or Cmd-B, or
4. As a Git pre-commit hook, so that it runs on any files you've changed before you check them in
Command-line tool
-------------------
**NOTE:** if you are using any of the following methods to install SwiftFormat on macOS 10.14.3 or earlier and are experiencing a crash on launch, you may need to install the [Swift 5 Runtime Support for Command Line Tools](https://support.apple.com/kb/DL1998). See [known issues](#known-issues) for details.
**Installation:**
You can install the `swiftformat` command-line tool on macOS or Linux using [Homebrew](http://brew.sh/). Assuming you already have Homebrew installed, just type:
```bash
$ brew install swiftformat
```
To update to the latest version once installed:
```bash
$ brew upgrade swiftformat
```
Alternatively, you can install the tool on macOS or Linux by using [Mint](https://github.com/yonaskolb/Mint) as follows:
```bash
$ mint install nicklockwood/SwiftFormat
```
Or if you prefer, you can check out and build SwiftFormat manually on macOS, Linux or Windows as follows:
```bash
$ git clone https://github.com/nicklockwood/SwiftFormat
$ cd SwiftFormat
$ swift build -c release
```
If you are installing SwiftFormat into your project directory, you can use [CocoaPods](https://cocoapods.org/) on macOS to automatically install the swiftformat binary along with your other pods - see the Xcode build phase instructions below for details.
Another option is to include the binary artifactbundle in your `Package.swift`:
```swift
.binaryTarget(
name: "swiftformat",
url: "https://github.com/nicklockwood/SwiftFormat/releases/download/0.53.9/swiftformat-macos.artifactbundle.zip",
checksum: "CHECKSUM"
),
```
If you would prefer not to use a package manager, you can build the command-line app manually:
1. open `SwiftFormat.xcodeproj` and build the `SwiftFormat (Application)` scheme.
2. Drag the `swiftformat` binary into `/usr/local/bin/` (this is a hidden folder, but you can use the Finder's `Go > Go to Folder...` menu to open it).
3. Open `~/.bash_profile` in your favorite text editor (this is a hidden file, but you can type `open ~/.bash_profile` in the terminal to open it).
4. Add the following line to the file: `alias swiftformat="/usr/local/bin/swiftformat --indent 4"` (you can omit the `--indent 4`, or replace it with something else. Run `swiftformat --help` to see the available options).
5. Save the `.bash_profile` file and run the command `source ~/.bash_profile` for the changes to take effect.
**Usage:**
If you followed the installation instructions above, you can now just type
```bash
$ swiftformat .
```
(that's a space and then a period after the command) in the terminal to format any Swift files in the current directory. In place of the `.`, you can instead type an absolute or relative path to the file or directory that you want to format.
**WARNING:** `swiftformat .` will overwrite any Swift files it finds in the current directory, and any subfolders therein. If you run it in your home directory, it will probably reformat every Swift file on your hard drive.
To use it safely, do the following:
1. Choose a file or directory that you want to apply the changes to.
2. Make sure that you have committed all your changes to that code safely in git (or whatever source control system you use).
3. (Optional) In Terminal, type `swiftformat --inferoptions "/path/to/your/code/"`. This will suggest a set of formatting options to use that match your existing project style (but you are free to ignore these and use the defaults, or your own settings if you prefer).
The path can point to either a single Swift file or a directory of files. It can be either be absolute, or relative to the current directory. The `""` quotes around the path are optional, but if the path contains spaces then you either need to use quotes, or escape each space with `\`. You may include multiple paths separated by spaces.
4. In Terminal, type `swiftformat "/path/to/your/code/"`. The same rules apply as above with respect to paths, and multiple space-delimited paths are allowed.
If you used `--inferoptions` to generate a suggested set of options in step 3, you should copy and paste them into the command, either before or after the path(s) to your source files.
If you have created a [config file](#config-file), you can specify its path using `--config "/path/to/your/config-file/"`. Alternatively, if you name the file `.swiftformat` and place it inside the project you are formatting, it will be picked up automatically.
5. Press enter to begin formatting.
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
一个简洁优雅的词典翻译_macOS_App。开箱即用,支持离线_OCR_识别,支持有道词典,_苹果_Easydict.zip (1017个子文件)
.autocorrectrc 2KB
.clang-format 2KB
RACSignalProvider.d 222B
RACCompoundDisposableProvider.d 190B
easydict 360B
Easydict-debug.entitlements 375B
Easydict.entitlements 305B
Gemfile 56B
.gitignore 2KB
RACSignal+Operations.h 33KB
RACmetamacros.h 30KB
AFURLSessionManager.h 30KB
RACSignal.h 23KB
AFURLRequestSerialization.h 22KB
AFHTTPSessionManager.h 20KB
RACSequence.h 18KB
RACStream.h 14KB
AFURLResponseSerialization.h 12KB
JLRoutes.h 10KB
RACTuple.h 9KB
FBKVOController.h 9KB
AFNetworkReachabilityManager.h 8KB
MASConstraint.h 8KB
JLRRouteDefinition.h 7KB
RACScheduler.h 7KB
MASUtilities.h 6KB
MMLog.h 6KB
EZQueryResult.h 6KB
EZYoudaoDictModel.h 6KB
AFSecurityPolicy.h 6KB
MASConstraintMaker.h 6KB
EZLanguageModel.h 5KB
TTTDictionary.h 5KB
EZQueryService.h 5KB
View+MASAdditions.h 5KB
RACCommand.h 5KB
View+MASShorthandAdditions.h 5KB
NSObject+RACPropertySubscribing.h 5KB
JLRRouteHandler.h 5KB
RACKVOChannel.h 5KB
NSData+CommonCrypto.h 4KB
RACEXTScope.h 4KB
ReactiveObjC.h 4KB
EZEnumTypes.h 4KB
NSObject+RACSelectorSignal.h 4KB
XPMMutableAttributedArray.h 4KB
JLRRouteRequest.h 4KB
EZBaiduTranslateResponse.h 3KB
RACEXTRuntimeExtensions.h 3KB
XPMArgumentSignature.h 3KB
NSString+EZUtils.h 3KB
MMMake.h 3KB
EZButton.h 3KB
RACChannel.h 3KB
EZWindowManager.h 3KB
EZLanguageManager.h 3KB
NSArray+MASAdditions.h 3KB
ReactiveObjC-umbrella.h 3KB
JLRRouteResponse.h 3KB
EZDeepLTranslateResponse.h 3KB
EZYoudaoTranslateResponse.h 2KB
ToastWindowController.h 2KB
EZError.h 2KB
RACEXTKeyPathCoding.h 2KB
MMOrderedDictionary.h 2KB
EZQueryModel.h 2KB
RACSubscriptingAssignmentTrampoline.h 2KB
EZConst.h 2KB
EZQueryView.h 2KB
EZEventMonitor.h 2KB
NSObject+RACLifting.h 2KB
NSObject+RACKVOWrapper.h 2KB
RACMulticastConnection.h 2KB
JLRParsingUtilities.h 2KB
EZBaseQueryViewController.h 2KB
NSInvocation+RACTypeParsing.h 2KB
MASConstraint+Private.h 2KB
RACCompoundDisposable.h 2KB
EZConstKey.h 2KB
RACEvent.h 2KB
RACSubscriber.h 2KB
RACSerialDisposable.h 2KB
NSObject+FBKVOController.h 2KB
EZLocalStorage.h 2KB
NSData+Base64.h 2KB
EZAudioPlayer.h 2KB
AFNetworking.h 2KB
AFCompatibilityMacros.h 2KB
EZCoordinateUtils.h 2KB
EZBingConfig.h 1KB
RACTestScheduler.h 1KB
RACQueueScheduler+Subclass.h 1KB
EZBingTranslateModel.h 1KB
NSColor+MyColors.h 1KB
NSString+EZConvenience.h 1KB
RACKVOProxy.h 1KB
MASViewConstraint.h 1KB
EZWebViewTranslator.h 1KB
EZTableTipsCell.h 1KB
DictionaryKit.h 1KB
共 1017 条
- 1
- 2
- 3
- 4
- 5
- 6
- 11
资源评论
好家伙VCC
- 粉丝: 2304
- 资源: 9142
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- IP网络的仿真及实验.doc
- 学习路之uniapp-goEasy入门
- 多边形框架物体检测26-YOLO(v5至v11)、COCO数据集合集.rar
- 基于Python和OpenCV的人脸识别签到系统的开发与应用
- course_s2_ALINX_ZYNQ_MPSoC开发平台Vitis应用教程V1.01.pdf
- 基于51单片机开发板设计的六位密码锁
- course_s5_linux应用程序开发篇.pdf
- course_s4_ALINX_ZYNQ_MPSoC开发平台Linux驱动教程V1.04.pdf
- course_s0_Xilinx开发环境安装教程.pdf
- 多边形框架物体检测20-YOLO(v5至v11)、COCO、CreateML、Paligemma、TFRecord、VOC数据集合集.rar
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功