I am currently building code that I would really like to use as a framework by being able to import MyCustomFramework
as I would with Apple frameworks (in the future I would also like to distribute them).
I have some questions about that :
- What is the easiest way to build a framework as what I want? Is this possible to do it directly in Xcode or do I need to use command line tools in the Terminal?
- Will this framework be compatible with multiple platforms (I am thinking about all Apple platforms but also about other platforms supported by Swift such as Linux).
- What is exactly the link between Swift frameworks and the Swift Package Manager ? Do I need SPM to build my framework or is this two different tools?
Thank you.
Currently, Swift Package Manager (SPM) and Xcode Frameworks follow different paths. For Linux, you have to follow the SPM path since the only way to compile a Linux swift application is to use SPM. For macOS command line apps, you can follow the SPM path as well. For iOS apps and macOS UI apps, you have to follow the Xcode Frameworks path.
For the SPM path, you make the project of your framework SPM-enabled: add
Package.swift
file and set the file layout of your project according to SPM conventions. The project also has to be a git repository. Then the git repository of your project can be specified as a dependency to other SPM-enabled frameworks/applications. Each SPM-enabled project can be converted to an Xcode project any time by usingswift package generate-xcodeproj
command.The Xcode Frameworks path is the standard, pre-SPM way of working with frameworks with Xcode, which is described elsewhere. You create an Xcode Project that will define your framework.
So, if you want your framework to be used both in SPM-enabled projects for Linux and macOS command line apps, and in Xcode-enabled projects for iOS and macOS UI apps, you have to follow the dual path. You make your project SPM-enabled and add an Xcode Project which will define your framework. You will have to maintain your project information twice - in
Package.swift
file and in the Xcode Project.