Embedding Sample App inside Swift Package

Ratul Chhibber
2 min readJun 21, 2021

So you finally plan to harness the power of Swift Packages for sharing your custom code.

Source: Unsplash

You may need a Sample App for the following reasons-

  1. During the development phase, you may like to simultaneously test- the implementation of your Swift Package.
  2. Once ready, showcasing the usage of your Swift Package.

This can be achieved by embedding a sample app inside a swift package-

Steps:

  1. Create a swift package: Example-
    mkdir SPMAppKit
    cd SPMAppKit
    swift package init — name SPMAppKit
  2. Open Package.swift
  3. Create a New App (SampleApp using File > New > Project > iOS > App) in the same hierarchy as Sources in your Swift Package directory (SPMAppKit here).

4. Now close the SwiftPackage(from Xcode) and open the SampleApp.

5. Drag and drop the base folder of the Swift Package inside the SampleApp

Base Folder: Swift Package
Once Swift Package is added locally (drag and drop)

6. Add the Swift Package inside the Framework, Libraries and Embedded Contents of the SampleApp.

Cheers, now you are all set to work on the sample app!

--

--