Skip to content

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

Open
chrfalch wants to merge 1 commit into
react-native-picker:masterfrom
chrfalch:chrfalch/spm-pkg-picker
Open

chrfalch wants to merge 1 commit into
react-native-picker:masterfrom
chrfalch:chrfalch/spm-pkg-picker

Conversation

@chrfalch

Copy link
Copy Markdown

Summary

React Native 0.88 can link native libraries with Swift Package Manager (SwiftPM) instead of CocoaPods. This PR adds SwiftPM support for iOS. CocoaPods users see no change, and no source files change.

  • New Package.swift at the repo root. React Native's SwiftPM autolinker uses it only when an app runs in SwiftPM mode.
  • package.json: Package.swift is added to files, and swiftpmConfig.name is set to RNCPicker, the same name the podspec uses.

How to verify

  1. Create a React Native 0.88 app and add this branch as a dependency.
  2. Run npx react-native spm add --deintegrate --yes in the app.
  3. Build for the iOS simulator in Debug. It should print BUILD SUCCEEDED.
  4. Run the app. The picker shows, and selecting an item calls onValueChange.

I did these steps on an iPhone simulator (iOS 27) with React Native 0.88.0.

Details

  • Target name. The SwiftPM target is RNCPickerTarget; the product is RNCPicker. If the target is named RNCPicker, SwiftPM treats ios/RNCPicker.h as an umbrella header and then rejects the RNCPicker.xcodeproj folder next to it, even when it is excluded. React Native links only the product, so apps never see the target name.
  • RCT_NEW_ARCH_ENABLED. CocoaPods gets this define from install_modules_dependencies. SwiftPM does not, so Package.swift sets it. Without it, the Fabric component compiles empty and is never registered.
  • Platforms. iOS only. React Native's SwiftPM binaries have no tvOS or macOS slices, so the podspec stays the path for those platforms.
  • Relative paths. ../../../../xcframeworks and ../../../ios resolve from the folder where React Native's autolinker links the package (<app>/build/generated/autolinking/libs/RNCPicker). They are not meant to resolve from the repo itself.

Add a Package.swift so apps that use React Native's SwiftPM mode
(React Native 0.88+) can link the picker. CocoaPods users see no change.
swiftpmConfig.name keeps the podspec name, RNCPicker.
@chrfalch
chrfalch requested a review from Naturalclar as a code owner October 28, 2026 10:00
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.

1 participant