Quantcast
Viewing all articles
Browse latest Browse all 166

Local Swift package and app targets

Hello,
Quite new at working with SPM here.

In our project, we have 2 app targets (each has its own set of assets that apply). Recently, we have created a local Swift package that should loads colors and fonts based on the target that runs. The styles are stored in 2 enum files containing static properties. The challenge is that the package has no context about the target that runs. Is there a recommended way the package can be made 'aware' of the running target?

One possibility would be to pass a value in the init of the package that represents the selected target. However, this is not ideal since in the code we have to manually select which style to load. With quite a few styles to work, I do wonder if we could avoid the need for the switch statement and write this in a more efficient way.
Thank you!

public init(target: String) {
        switch target {
        case "target-x":
            primarycolor = X.primarycolor
        case "target-y":
            primarycolor = Y.primarycolor
        default:
            primarycolor = .white
}

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 166

Trending Articles