The Swift package manager, or SwiftPM, currently has no support for iOS platform, however, it is still possible to use it for this purpose.
- Initialise a library package:
$ swift package init --type library
Package.swift(you could fin an example here).
- Create a
xcode.xcconfigfile, that will specify the platforms you want to support. For example:
SUPPORTED_PLATFORMS = iphoneos iphonesimulator IPHONEOS_DEPLOYMENT_TARGET = 9.0
- Then generate
.xcodeprojfile using this config:
$ swift package generate-xcodeproj --xcconfig-overrides xcode.xcconfig
- Create a workspace and add the generated project to it.
- Next, create a new project targeting iOS application and add it to the workspace too.
- Finally, add the frameworks of the library plus its dependencies as embedded binaries of the iOS project.
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?
- When you create or add a new file you need to take care of the target where the file is added (this could be modify in the
Target Membershipsection of the
- Each time you add dependencies, you must re-generate
.xcodeprojusing the command we used at step 4.
- The code inside the library need to be marked as public to be visible outside of the framework.
- Before pressing ⌘B or ⌘R check the target your are building 😅...
An example? 🙏
Sure 😇, you could find a simple project using this technique here.