From 46a302e86fce121ae08d6f4532a36e75f1fe5a49 Mon Sep 17 00:00:00 2001 From: Christian Falch Date: Wed, 28 Oct 2026 11:00:11 +0100 Subject: [PATCH] feat(ios): add Swift Package Manager support 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. --- Package.swift | 39 +++++++++++++++++++++++++++++++++++++++ package.json | 8 ++++++-- 2 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 Package.swift diff --git a/Package.swift b/Package.swift new file mode 100644 index 000000000..cf7b2ff9b --- /dev/null +++ b/Package.swift @@ -0,0 +1,39 @@ +// swift-tools-version: 6.0 +// Built through React Native's SwiftPM autolinker, which links this package at +// /build/generated/autolinking/libs/RNCPicker. The relative package paths +// resolve from there to the app's React Native xcframeworks and codegen output. +// This file has no scaffolder marker, so `react-native spm scaffold` leaves it alone. + +import PackageDescription + +let package = Package( + name: "RNCPicker", + platforms: [.iOS("15.1")], + products: [ + .library(name: "RNCPicker", targets: ["RNCPickerTarget"]), + ], + dependencies: [ + .package(name: "ReactNative", path: "../../../../xcframeworks"), + .package(name: "React-GeneratedCode", path: "../../../ios"), + ], + targets: [ + // Not named RNCPicker: SwiftPM would take ios/RNCPicker.h as the umbrella + // header and then reject the RNCPicker.xcodeproj folder next to it, + // excluded or not. React Native links only the product, so the target + // name is free. + .target( + name: "RNCPickerTarget", + dependencies: [.product(name: "ReactHeaders", package: "ReactNative"), .product(name: "ReactNativeHeaders", package: "ReactNative"), .product(name: "ReactNativeDependenciesHeaders", package: "ReactNative"), .product(name: "ReactAppHeaders", package: "React-GeneratedCode")], + path: "ios", + exclude: ["RNCPicker.xcodeproj"], + publicHeadersPath: ".", + // CocoaPods gets RCT_NEW_ARCH_ENABLED from install_modules_dependencies; + // without it every Fabric source compiles empty and the component is + // never registered. + cSettings: [.define("RCT_NEW_ARCH_ENABLED", to: "1"), .headerSearchPath(".")], + cxxSettings: [.define("RCT_NEW_ARCH_ENABLED", to: "1"), .headerSearchPath("."), .define("DEBUG", .when(configuration: .debug)), .define("NDEBUG", .when(configuration: .release))], + linkerSettings: [.linkedFramework("UIKit"), .linkedFramework("Foundation"), .linkedFramework("CoreGraphics")] + ), + ], + cxxLanguageStandard: .cxx20 +) diff --git a/package.json b/package.json index 5c2e2f5f2..779377d12 100644 --- a/package.json +++ b/package.json @@ -145,7 +145,8 @@ "typings", "windows", "react-native.config.js", - "RNCPicker.podspec" + "RNCPicker.podspec", + "Package.swift" ], "react-native-builder-bob": { "source": "js", @@ -180,5 +181,8 @@ "workspaces": [ "example" ], - "packageManager": "yarn@4.1.1" + "packageManager": "yarn@4.1.1", + "swiftpmConfig": { + "name": "RNCPicker" + } }