How to support Swift Package Manager for existing projects
Issue #445
How to add SPM
- Run
swift package init
- Check enum for version for each platform https://developer.apple.com/documentation/swift_packages/supportedplatform/tvosversion
1 | // swift-tools-version:5.1 |
To test, swift test
to test locally, this should validate Package.swift
too
Support multiple platform
To support multiple platform, use platform check
1 | #if canImport(UIKit) |
Use sources in Target
- https://developer.apple.com/documentation/swift_packages/target/2880339-sources
- https://github.com/onmyway133/EasyClosure/blob/master/Package.swift
If this property is nil, all valid source files in the target’s path will be included and specified paths are relative to the target path.
A path can be a path to a directory or an individual source file. In case of a directory, the Swift Package Manager searches for valid source files recursively inside it.
1 | .target( |
Error
error: target ‘EasyClosuremacOS’ has sources overlapping sources
How to use
- SPM packages are at
DerivedData/MyApp/SourcePackages/checkouts
- Delete DerivedData for Xcode to fetch new contents from GitHub
- Clean build folder as Xcode often caches changes from frameworks