Use Swift Package Manager with iOS projects

The Swift package manager, or SwiftPM, currently has no support for iOS platform, however, it is still possible to use it for this purpose.

How?

  1. Initialise a library package:
    $ swift package init --type library
  2. Edit Package.swift (you could fin an example here).
  3. Create a xcode.xcconfig file, that will specify the platforms you want to support. For example:
    SUPPORTED_PLATFORMS = iphoneos iphonesimulator
    IPHONEOS_DEPLOYMENT_TARGET = 9.0
    
  4. Then generate .xcodeproj file using this config:
    $ swift package generate-xcodeproj --xcconfig-overrides xcode.xcconfig
  5. Create a workspace and add the generated project to it.
  6. Next, create a new project targeting iOS application and add it to the workspace too.
  7. Finally, add the frameworks of the library plus its dependencies as embedded binaries of the iOS project.

That's it!

Wait⁉️ Where do I put my code?

You have the choice 🤗, but by putting it inside the library code base you will be able to do Playground-Driven Development, working on parts of the app inside a playground to quickly iterate on new features or bug fixes.

Any precautions to take?

An example? 🙏

Sure 😇, you could find a simple project using this technique here.