首页 > 解决方案 > 如何在 Xcode 中添加可由 Swift 包管理器运行的可执行文件?

问题描述

我使用 SPM 来初始化包,然后生成 xcodeproj 以在 Xcode 中进行编辑。我在 Xcode 中添加了一个可执行文件,但 SPM 在构建时没有选择它。如果我使用 SPM 再次运行 generate-xcodeproj,可执行产品就消失了。我查看了 .build 文件夹,可执行文件不存在。现在这是我的 Package.swift:

// swift-tools-version:4.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
    name: "Swerver",
    products: [
        .library(
            name: "Swerver",
            targets: ["Swerver"]),
    ],
    dependencies: [
    .package(url: "https://github.com/IBM-Swift/BlueSocket.git", from: "1.0.8"),
    ],
    targets: [
        .target(
            name: "Swerver",
            dependencies: [
                "Socket"
            ],
            path: "Sources/SwerverCore"),
        .testTarget(
            name: "SwerverTests",
            dependencies: ["Swerver"]),
    ]
)

标签: swiftxcodeswift-package-manager

解决方案


You can't add an executable in Xcode and have it picked up by the Swift Package Manager. You need to add it in the Package.swift file and regenerate the Xcode project.

Alternatively, add the executable to a new project that references the generated project.


推荐阅读