Aswath
Aswath

Reputation: 1480

Issue adding a development swift package to an app

I am trying to add a local in-development Swift Package to my project. I followed this Organizing Your Code with Local Packages. Using Xcode 12 beta.

I created a swift package named "MyLibrary". Then I move the code from my app to the Sources folder in my swift package. I then close the swift package project in Xcode and drag and drop the package folder to my app.

However, here is where I am stuck. I need to add MyLibrary target into the Link binary with Libraries section in the build phases. I don't see the library/ framework target listed in the dialog.

I am listing below just the products and targets for the swift package. I tried adding a binaryTarget too, but that did not help.

products: [
    .library(
        name: "MyLibrary",
        targets: ["MyLibrary"]),
],
targets: [
    .target(
        name: "MyLibrary",
        dependencies: []),
    .testTarget(
        name: "MyLibraryTests",
        dependencies: ["MyLibrary"]),
]

Upvotes: 0

Views: 901

Answers (1)

matt
matt

Reputation: 534885

I will give step by step instructions. We will start completely from scratch in this example.

  1. File > New > Project. Select the iOS App template. Save the project as My Project; other settings Storyboard, UIKit App Template, Swift. Create it on the Desktop.

  2. File > New > Swift Package. Okay, this is the hard part. See at the bottom of the save dialog where it says Add to? Choose MyProject. The Group should then be MyProject too. Both icons should be blue project icons. Now save as MyLibrary, on the Desktop.

  3. Now we are in MyProject. Select MyProject, the project, at the top of the project navigator. On the right, choose the target MyProject. Scroll down to Frameworks, Libraries, and Embedded Content and click the Plus button. You will see right at the top Workspace, then MyLibrary the "framework", the MyLibrary the "library". Choose the third one, MyLibrary the "library", and click Add.

Upvotes: -1

Related Questions