Xcode添加到项目为空

amrnrhlw  于 2023-06-24  发布在  其他
关注(0)|答案(1)|浏览(157)

我使用以下命令行创建了一个项目:

swift package init --type executable

然后,我想通过xcode向项目添加一个库。不幸的是,在添加到项目中显示了一个空字段,所以我无法将其添加到项目中:

如何使项目在Add to Project下拉列表中可见?
Package.swift文件的内容

import PackageDescription

let package = Package(
    name: "redix-svc-test",
    targets: [
        // Targets are the basic building blocks of a package, defining a module or a test suite.
        // Targets can depend on other targets in this package and products from dependencies.
        .executableTarget(
            name: "redix-svc-test")
    ]
)
wqsoz72f

wqsoz72f1#

你不需要,至少在当前版本的Xcode中不需要。该下拉列表适用于Xcode生成的项目,如框架和应用程序。
相反,您应该按下Copy dependency,这会将依赖项声明复制到剪贴板上,然后手动添加到Package.swift中。
当然,也不要忘记声明可执行目标的依赖项。
例如:

let package = Package(
    name: "redix-svc-test",
    dependencies: [
        // this is the line Xcode copied
        .package(url: "https://github.com/vapor/websocket-kit", .upToNextMajor(from: "2.0.0")),
    ],
    targets: [
        .executableTarget(
            name: "redix-svc-test",
            // and this is what you must come up with yourself
            dependencies: [.product(name: "WebSocketKit", package: "websocket-kit")]),
    ]
)

相关问题