A bridging header allows Swift code to access Objective-C libraries and native modules. Here's how to set it up.
Setup Steps
Step 1: Create the Bridging Header File
- Right-click on your project folder in Xcode
- Select New File from Template
- Choose Header file
Step 2: Configure the File
- Click Header file template
- Name it:
YourAppName-Bridging-Header.h - Select all targets (main app, development, production)
- Click Create
Step 3: Set the Bridging Header Path
For each target:
- Go to Build Settings
- Search for "Objective-C Bridging Header"
- Set path:
YourAppName/YourAppName-Bridging-Header.h
Step 4: Import Your Headers
Open the bridging header and import what you need:
// React Native Config
#import "RNCConfig.h"
// Google Maps
#import <GoogleMaps/GoogleMaps.h>
// Your custom modules
#import "CustomNativeModule.h"
Step 5: Use in AppDelegate.Swift
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Access environment variables
if let apiKey = RNCConfig.env(for: "API_KEY") {
GMSServices.provideAPIKey(apiKey)
}
// Initialize Firebase
FirebaseApp.configure()
return true
}
}
Step 6: Clean and Build
- Clean:
Cmd + Shift + K - Build:
Cmd + B - Run:
Cmd + R
Project Structure
YourAppName/
├── ios/
│ ├── YourAppName/
│ │ ├── AppDelegate.swift
│ │ ├── YourAppName-Bridging-Header.h ✅
│ │ └── Info.plist
│ └── Pods/
└── package.json
Found this helpful? Drop a ❤️ below! 🚀




Top comments (0)