← 返回命令列表

Linux command

swift 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Start REPL

swift

Run script

swift [script.swift]

Build package

swift build

Build release

swift build -c release

Run package

swift run

Run tests

swift test

Create new package

swift package init --type [executable]

Show dependencies

swift package show-dependencies

说明

swift is the Swift programming language compiler and package manager. It builds, runs, and tests Swift applications. The REPL provides interactive Swift execution. It's useful for experimentation and learning. Swift Package Manager handles dependencies and builds. Package.swift defines targets, dependencies, and products. Debug builds are fast to compile with debugging support. Release builds optimize for performance. Testing integrates XCTest framework. Tests run with swift test, supporting parallel execution. Cross-platform support includes Linux and Windows beyond Apple platforms. Server-side Swift is a common use case.

参数

build
Build the package.
run _TARGET_
Build and run.
test
Run tests.
package init
Create new package.
package update
Update dependencies.
package resolve
Resolve dependencies.
-c _CONFIG_
Build configuration (debug, release).
-Xswiftc _FLAG_
Pass flag to compiler.
--version
Show version.
--help
Show help.

FAQ

What is the swift command used for?

swift is the Swift programming language compiler and package manager. It builds, runs, and tests Swift applications. The REPL provides interactive Swift execution. It's useful for experimentation and learning. Swift Package Manager handles dependencies and builds. Package.swift defines targets, dependencies, and products. Debug builds are fast to compile with debugging support. Release builds optimize for performance. Testing integrates XCTest framework. Tests run with swift test, supporting parallel execution. Cross-platform support includes Linux and Windows beyond Apple platforms. Server-side Swift is a common use case.

How do I run a basic swift example?

Run `swift` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does build do in swift?

Build the package.