2

I have created a new Swift package and trying to use the RxSwift dependency within it. I followed these instructions to add the dependency but my package is unable to build after this with the following error:

product 'RxCocoa' required by package 'mylibrary' target 'MyLibrary' not found.

My package manifest is here:

// swift-tools-version: 5.8
import PackageDescription

let package = Package(
    name: "MyLibrary",
    products: [them visible to other packages.
        .library(
            name: "MyLibrary",
            targets: ["MyLibrary"]),
    ],
    dependencies: [
        .package(url: "https://github.com/ReactiveX/RxSwift.git", .exact("6.5.0"))
    ],
    targets: [
        .target(
            name: "MyLibrary",
            dependencies: ["RxSwift", "RxCocoa"]),
        .testTarget(
            name: "MyLibraryTests",
            dependencies: ["MyLibrary"]),
    ]
)

enter image description here

I'm using Xcode 14.3. How should I add the RxSwift dependency to the package.

Mando
  • 11,414
  • 17
  • 86
  • 167

1 Answers1

4

RxCocoa isn't its own package, it's a product in the RxSwift package. Your dependencies need to be set up like this:

dependencies: [
    "RxSwift",
    .product(name: "RxCocoa", package: "RxSwift"),
]
Daniel T.
  • 32,821
  • 6
  • 50
  • 72
  • Thanks for clarifying! And it works great. Although the [RxSwift docs](https://github.com/ReactiveX/RxSwift#swift-package-manager) clearly defines dependency differently and (turned out) incorrectly – Mando Apr 14 '23 at 19:16