evgenyneu / keychain-swift

Helper functions for saving text in Keychain securely for iOS, OS X, tvOS and watchOS.
MIT License
2.82k stars 345 forks source link

[Solved] Error when adding KeychainSwift as Swift Package to my own Swift Package #169

Closed Svantulden closed 11 months ago

Svantulden commented 11 months ago

Description

When I added this library to my own Swift Package, I couldn't seem to link the library to my package. My setup in the Package.swift:

// swift-tools-version: 5.9

import PackageDescription

let package = Package(
    name: "MyTarget",
    platforms: [
        .iOS(.v13)
    ],
    products: [
        .library(
            name: "MyTarget",
            targets: ["MyTarget"]
        ),
    ],
    dependencies: [
        .package(url: "https://github.com/evgenyneu/keychain-swift.git", from: "20.0.0")
    ],
    targets: [
        .target(
            name: "MyTarget",
            dependencies: [
                "KeychainSwift"
            ]
        )
    ]
)

Which gave the error:

product 'KeychainSwift' required by package 'mytarget' target 'MyTarget' not found.

I tried many things, like changing the name to keychain-swift, as the compiler sometimes gave an extra message at the error like: valid product names are 'keychain-swift', but that also didn't work.

Cause:

This issue happens when packages specify a different Package.name property compared to the github repo name. E.g. KeychainSwift's repo name is keychain-swift but the Package.swift says is called KeychainSwift.

Source

Solution:

I'm posting this here so it hopefully helps someone else as well. I don't know if it should be updated in the Readme.md, if so, I can make a PR for that.

The solution is to specify a name as well for my Package.swift:

    dependencies: [
        .package(name: "KeychainSwift", url: "https://github.com/evgenyneu/keychain-swift.git", from: "20.0.0")
    ],
    targets: [
        .target(
            name: "MyTarget",
            dependencies: [
                "KeychainSwift"
            ]
        )
    ]
evgenyneu commented 11 months ago

Thanks for that, a PR would be great. :D

Svantulden commented 11 months ago

PR opened @ #170