Skip to content

feat(ios): add Swift Package Manager support - #1054

Open
chrfalch wants to merge 1 commit into
wonday:masterfrom
chrfalch:spm
Open

chrfalch wants to merge 1 commit into
wonday:masterfrom
chrfalch:spm

Conversation

@chrfalch

@chrfalch chrfalch commented Oct 27, 2026 •

Copy link
Copy Markdown

Summary

React Native 0.88 can build iOS libraries with Swift Package Manager (SwiftPM) instead of CocoaPods. react-native-pdf has no Package.swift, so apps that use SwiftPM cannot use it.

This PR adds SwiftPM support. CocoaPods users see no change, and no source file changes.

  1. Package.swift: the manifest that React Native's SwiftPM autolinking uses. It defines RCT_NEW_ARCH_ENABLED=1, because CocoaPods gets that define from install_modules_dependencies and the Fabric view needs it.
  2. The manifest excludes every root entry it does not use, so SwiftPM does not scan example/ or node_modules/ for resources.
  3. react-native-spm-prefix.h: a prefix header that matches the CocoaPods default.
  4. package.json: the Swift package name (swiftpmConfig.name) and the new files in files.

SwiftPM support also needs react-native-blob-util 1.1.1 or later. That release adds the Swift package name for blob-util (RonRadtke/react-native-blob-util#507). CocoaPods users can keep any blob-util version.

Would you like SwiftPM support in this library? I am glad to change the approach.

Test plan

  • New React Native 0.88.1 app, set up for SwiftPM with npx react-native spm add --deintegrate, with react-native-pdf from this branch and react-native-blob-util 1.1.1 from npm, without changes.
  • xcodebuild Debug and Release, iOS 27 simulator: both BUILD SUCCEEDED.
  • Release build, without Metro: the app loads and renders a 3-page PDF.
  • Not tested: tvOS (the podspec lists it; this manifest is iOS only).

React Native 0.88 can build libraries with Swift Package Manager instead of
CocoaPods, but react-native-pdf has no Package.swift, so SwiftPM apps cannot
use it.

This adds a Package.swift that React Native's SwiftPM autolinker uses, a
prefix header that matches the CocoaPods default, and package.json entries
for the Swift package name and the published files. CocoaPods users see no
change, and no source file changes.

- RCT_NEW_ARCH_ENABLED=1 is defined in the manifest, because CocoaPods gets it
  from install_modules_dependencies and the Fabric view needs it.
- The manifest excludes every root entry it does not use, so SwiftPM does
  not scan example/ or node_modules/ for resources, in a checkout and in an
  npm install.

Tested on React Native 0.88.0, iOS 27 simulator: Debug build succeeds, and a
3-page PDF loads and renders.
@chrfalch
chrfalch marked this pull request as ready for review November 9, 2026 10:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants