Integrating Swift Package Manager with React Native Libraries
Article Summary
Mike Grabowski from Callstack shows how React Native developers can finally use Swift Package Manager alongside CocoaPods. The catch? Your entire iOS project needs dynamic frameworks.
React Native has relied on CocoaPods for years, but Apple's Swift Package Manager is the future. Since React Native 0.75, there's been a way to integrate SPM packages through the spm_dependency helper. This article walks through using both remote and local SPM packages in your React Native libraries.
Key Takeaways
- spm_dependency helper enables SPM integration in React Native 0.75+
- Requires use_frameworks! with dynamic linkage across entire iOS project
- Local SPM package support coming in 0.84 (needs patch today)
- Monorepo teams can reference Swift packages within their codebase
- CocoaPods expected to become read-only and gradually phased out
React Native developers can now bridge the CocoaPods and SPM ecosystems, though adopting dynamic frameworks is mandatory and may impact performance or binary size.
About This Article
React Native libraries couldn't use local Swift packages in monorepos. The spm_dependency helper only worked with remote Git URLs, so developers had to find workarounds to handle local packages.
Callstack fixed spm_dependency to handle local packages alongside remote ones. The update uses File.exist() checks to create XCLocalSwiftPackageReference objects for local paths instead of XCRemoteSwiftPackageReference.
React Native libraries can now consume local Swift packages in monorepos with relative path resolution. You'll need to patch node_modules until React Native 0.84 comes out officially.