https://www.swift.org/getting-started/
https://www.swift.org/install/macos/
首先查看电脑是否已经安装 swift 工具链, 打开 终端输入如下命令:
➜ swift --version
swift-driver version: 1.120.5 Apple Swift version 6.1.2 (swiftlang-6.1.2.1.2 clang-1700.0.13.5)
Target: x86_64-apple-macosx15.0
如果上面的命令不能输出 swift 版本,说明你没有安装对应的工具链, 在苹果电脑有两种方式安装,最简单的方式是安装 xcode,
另一种方式 是 win,linux,mac 通用, 参考这里: www.swift.org/install/lin… 使用 swiftly 安装,具体自己看文档。
下一步安装 编辑器 这里使用 vscode, 参考这里 code.visualstudio.com/docs/langua…
Create a new Swift project
To create a new Swift project, you can use the Swift: Create New Project... command in the Swift extension to guide you through the process. You can find this command by opening the Command Palette and following the instructions below
// 运行 单个 swift 文件 例如: `Sources/main.swift`
➜ Sources swift main.swift