Xcode and spm

Here is how you use Swift package manager in your XCode app projects

The workflow:

  • Terminal: cd ~/dev/MyProject/ ๐Ÿ‘ˆ navigate to your project
  • Terminal: swift package init ๐Ÿ‘ˆ creates the initial SPM files
  • Add the bellow to your newly created Package.swift file:
/*basically adds Swift-utils as a third Party framework in your project    */
import PackageDescription
let package = Package(
    name: "MyProject",
	dependencies: [
		.Package(url: "https://github.com/eonist/swift-utils.git", Version(0, 0, 0, prereleaseIdentifiers: ["alpha", "3"]))
  • Terminal: swift build ๐Ÿ‘ˆ downloads the dependencies from github and builds binaries (aka .framework)
  • Terminal: swift package generate-xcodeproj ๐Ÿ‘ˆ Creates an XCode project that has .framework files
  • XCode: Open MyProject.xcodeproj and then: file -> Target -> Cocoa app -> Name it MyApp
  • XCode: Select MyProject -> General -> Targets -> MyApp -> Embedded binaries -> Add the Utils.framework
  • XCode: Menu -> Product -> Scheme -> MyApp then hit cmd + b ๐Ÿ‘ˆ This will build the frameworks
  • XCode: Add: @testable import Utils to AppDelegate.swift and print(StringParser.sansSuffix("blue")) inside the applicationDidFinishLaunching method
  • XCode: Run the MyApp and it will now print blu

Why is this awesome?

  1. When you develop your app. You use binaries but you have full access to third-party code. ๐Ÿ”‘
  2. When you need to download a new version of third party libs: Terminal: swift package update
  3. Supports nested frameworks ๐Ÿ‘ˆ โ€œholy grail of Dependency managementโ€
  4. Supports CI, check this
  5. If you are developing on your own third-party modules you can integrate this workflow with no extra steps. as the packages are pure .git projects. Just commit back to github repo directly from inside your project. Either by git checkout master or git push origin HEAD:master
  6. If you add code to third-party dependencies then they are embedded in the binaries automatically.


  • [ ] Investigate buildMetadataIdentifier ๐Ÿ‘ˆ Supposedly it enables you to target single commit ids rather than version tags
  • [ ] Implement CI Travis
  • [ ] C - code in SPM: here

Related Posts

Startup Oslo

โ€œKulturhusetโ€ is a new place in the startup scene in Oslo. Itโ€™s โ€œfreeโ€ and can be used by anyone to collaborate or work on different projects.

Infinite Tree List

My notes on Infinite tree list

Protocol Inheritance

My notes on Protocol Inheritance

Protocol Ambiguity

How to differentiate protocol ambiguity

The Ultimate Xcode Workflow

Spend zero time managing dependencies

Faster Xcode With Spm

How you can speed up compile times in XCode with Swift Package Manager

Spm And Ci Travis

My notes on Swift PM + CI Travis

Spm And Nested Frameworks

My notes on Swift package manager + XCode + Nested frameworks

Carthage And Nested Frameworks

A few workflows concerning Carthage and nested framework

Two Finger Swipe

Notes on implementing two finger swipe for macOS