Swift Development

Swift Development 0.0.25

分类:工具软件

版本:0.0.25

浏览:46

日期:06.13

探索如何在VSCode中设置Swift开发环境。本文详细介绍了如何安装SweetPad、配置触发任务、Swift和CodeLLDB,助您高效开发Swift项目。

ios
立即下载

在 VSCode 中开发 Swift 项目需要配置 SweetPad、触发任务、Swift 和 CodeLLDB。如果您在 VSCode 中打开 Xcode 项目,将会提示您准备 Swift 开发环境。您也可以通过按 (Cmd Shift P) > (Help: Welcome) 进行设置,或者按照以下详细步骤进行配置:

1. 安装所有必要工具

要确保您拥有使用 SweetPad 工作所需的所有必要工具,请运行以下命令,使用 Homebrew 安装所需软件:

# 如果尚未安装 Homebrew,请先安装
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

然后安装以下工具:

# 安装 swift-format
brew install swift-format

# 安装 XcodeGen
brew install xcodegen

# 安装 SwiftLint
brew install swiftlint

# 安装 xcbeautify
brew install xcbeautify

# 安装 xcode-build-server
brew install xcode-build-server

# 安装 ios-deploy
brew install ios-deploy

# 安装 tuist
brew install --cask tuist

2. 创建 .vscode 文件夹

3. 在 .vscode/settings.json 中添加以下内容

{
    "triggerTaskOnSave.tasks": {
        "sweetpad: build": [
            "**/*.swift"
        ]
    },
    "triggerTaskOnSave.on": true,
    "triggerTaskOnSave.showNotifications": false,
    "triggerTaskOnSave.restart": true,
    "triggerTaskOnSave.delay": 1000,
    "triggerTaskOnSave.resultIndicatorResetTimeout": 5,
    "workbench.colorCustomizations": {},
    "sweetpad.format.args": [
        "--in-place",
        "--configuration",
        ".vscode/.swift-format",
        "${file}"
    ],
    "[swift]": {
        "editor.defaultFormatter": "sweetpad.sweetpad",
        "editor.formatOnSave": true,
    }
}

4. 在 .vscode/.swift-format 中添加以下内容

{
    "indentation" : {
      "spaces" : 4
    },
    "insertSpaces" : true,
    "spacesAroundRangeFormationOperators" : false,
    "tabWidth" : 8,
    "version" : 1
}

5. 在 .vscode/launch.json 中添加以下内容

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "sweetpad-lldb",
      "request": "launch",
      "name": "Attach to running app (SweetPad)",
      "preLaunchTask": "sweetpad: launch"
    }
  ]
}

6. 在 .vscode/tasks.json 中添加以下内容

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "sweetpad",
            "action": "build",
            "problemMatcher": [
                "$sweetpad-watch",
                "$sweetpad-xcodebuild-default",
                "$sweetpad-xcbeautify-errors",
                "$sweetpad-xcbeautify-warnings"
            ],
            "label": "sweetpad: build",
            "detail": "Build the app",
            "isBackground": true,
            "presentation": {
                "reveal": "silent",
                "panel": "dedicated",
                "showReuseMessage": false,
                "clear": true
            }
        },
        {
            "type": "sweetpad",
            "action": "launch",
            "problemMatcher": [
                "$sweetpad-watch",
                "$sweetpad-xcodebuild-default",
                "$sweetpad-xcbeautify-errors",
                "$sweetpad-xcbeautify-warnings"
            ],
            "label": "sweetpad: launch",
            "detail": "Build and Launch the app",
            "presentation": {
                "reveal": "always",
                "panel": "dedicated",
                "showReuseMessage": true,
                "clear": false
            }
        },
        {
            "type": "sweetpad",
            "action": "clean",
            "problemMatcher": [
                "$sweetpad-watch",
                "$sweetpad-xcodebuild-default",
                "$sweetpad-xcbeautify-errors",
                "$sweetpad-xcbeautify-warnings"
            ],
            "label": "sweetpad: clean",
            "detail": "Clean the app",
            "presentation": {
                "reveal": "always",
                "panel": "dedicated",
                "showReuseMessage": true,
                "clear": false
            }
        }
    ]
}

7. 生成构建服务器配置以支持自动完成

按 Cmd Shift P 并运行:

SweetPad: Create Build Server Config

如果一切顺利,您应该已经准备好在 VSCode 中开发 Swift 项目了!

最新下载

更多 ›

相关文章

更多 ›

课程推荐

更多 ›
首页