iosobjective-cxcodereact-nativeobjective-c-swift-bridge

How do I create an Objective-C bridging header?


I'm following this guide on adding OneSignal to React Native, and there is one section where is says:

Open NotificationService.m or NotificationService.swift and replace the whole file contents with the code below:

<provides code to add>

If you are using Swift, make sure to create a separate Objective-C Bridging Header for your OneSignalNotificationExtensionService and add the following import:

#import "RCTOneSignalExtensionService.h" Then you need to tell your Xcode project settings what your bridging header is named, like this.

I added the code they provided to NotificationService.swift because that's the only one of the two files that exists in my project. So I assume I'm "using swift" as they put it. The problem is that when they say to create a separate Objective-C Bridging Header, I don't know how to do that. All I've been able to find online is that when you import Objective-C code into your swift project, Xcode should automatically prompt you to create a bridging header. Xcode hasn't done that for me.

Does anyone know how I can create an Objective-C bridging header?


Solution

  • You have to create a new objective c class:

    You select New File

    then

    select cocoa touch class

    then you name it and specify as objective-c class at language

    select objective-c as language

    then you select your directory and hit create. At this point xcode is going to ask you whether or not you want to create bridging header. Yep do it.

    enter image description here

    And at the end it should look more or less like this at your project.

    Job done

    hope that helps you.