Swift Package Manager with iOS
This project demonstrates a working method for using Swift Package Manager (SPM) to manage the dependencies of an iOS project. It has been tested with Xcode 9.1, using Swift 4 and the SPM v4 description format.
Note: At this time there is no official support for iOS targets or the related system libraries in SPM.
To get started:
sudo gem install xcodeproj
ruby generate-project-dependencies.rbin the project root directory. This will pull down dependencies as defined in
Package.swiftand then generate and modify a Dependencies project which is then included as a sub-project by the example project.
Build the main target (you may need to manually build the target for the Dependencies sub-project).
This will build a simple app that depends on RxSwift. RxSwift was chosen because it shows how to handle modules generated from Objective-C.
The end result will be a standard iOS application, with Static Frameworks for each of its dependencies embedded within the bundle.
You can link the dependencies dynamically if you prefer, by removing the
config.build_settings['MACH_O_TYPE'] = 'staticlib' line in
generate-project-dependencies.rb. If you do this you will need to embed the dependencies in your main app target.
You can step through the commits to see what steps were taken, with a brief overview of the process below.
(This process hasn't been tested with Xcode 8.3 & Swift 3.1)
- Generate iOS App project with Xcode
- Generate swift package for Dependencies
- Create dummy source file for Dependencies (I've chosen to put this in
.deps-sourcesbut does not necessarily need to be hidden)
- Modify build settings in generated xcodeproj (this is done in
- Add Dependencies.xcodeproj as subproject of the main app xcodeproj
- Add a dependency (to RxSwift in this example) in Package.swift
- Link our App with the new Rx*.frameworks
- Write some sample code to verify that the import works
- Override MODULEMAP_FILE setting for non-Swift modules