Steps to achieve Swift Package Manager and XCode integration in 2019:
1) Create Dependencies.swift file
/yourproject/Dependencies/Sources/Dependencies.swift
(empty file)
2) Create macos.xcconfig file
/yourproject/Dependencies/Sources/macos.xcconfig
MACOSX_DEPLOYMENT_TARGET = 10.14
3) Create Package.swift file
/yourproject/Dependencies/Package.swift
// swift-tools-version:4.2
import PackageDescription
let package = Package(
name: "Dependencies",
products: [
.library(name: "Dependencies", type: .static, targets: ["Dependencies"])
],
dependencies: [
.package(url: "https://github.com/YourDependency/here.git", .upToNextMinor(from: "0.1.0"))
],
targets: [
.target(name: "Dependencies", dependencies: ["YourDependency"])
]
)
4) Generate Dependencies.xcodeproj and drag-and-drop into your existing project
swift package generate-xcodeproj --xcconfig-overrides Sources/macos.xcconfig
5) Import your dependency
import YourDependency
This is enough to make it work but you can make your life a bit easier with a few extra steps.
Additional (optional) steps:
6) Create ios.xcconfig file
/yourproject/Dependencies/Sources/ios.xcconfig
SDKROOT = iphoneos
SUPPORTED_PLATFORMS = iphonesimulator iphoneos
IPHONEOS_DEPLOYMENT_TARGET = 10.0
ARCHS = $(ARCHS_STANDARD)
VALID_ARCHS = $(ARCHS_STANDARD)
VALIDATE_PRODUCT = YES
LD_RUNPATH_SEARCH_PATHS = $(inherited) @executable_path/Frameworks
TARGETED_DEVICE_FAMILY = 1, 2
7) Add Pre-build action to your main project's iOS and macOS Schemes
iOS
echo "Building SPM Dependencies"
BASE_DIR="${PROJECT_DIR}/Dependencies"
cd ${BASE_DIR}
rm -fr Dependencies.xcodeproj
swift package update
swift package generate-xcodeproj --xcconfig-overrides Sources/ios.xcconfig
sleep 3
until [ -d "Dependencies.xcodeproj" ]
do
echo "File not found"
sleep 0.1
done
echo "File found"
exit
macOS
echo "Building SPM Dependencies"
BASE_DIR="${PROJECT_DIR}/Dependencies"
cd ${BASE_DIR}
rm -fr Dependencies.xcodeproj
swift package update
swift package generate-xcodeproj --xcconfig-overrides Sources/macos.xcconfig
sleep 3
until [ -d "Dependencies.xcodeproj" ]
do
echo "File not found"
sleep 0.1
done
echo "File found"
exit
8) Run your project and enjoy :)