0

I am trying to use the react-native-config with react-native configured with Swift.

Following the usage guide, it tells me to import #import "ReactNativeConfig.h".

I imported this inside of the bridging header, but it can't find it.

Does anyone know how to use this library with a react native app build with Swift?

R. de Ruijter
  • 513
  • 5
  • 13

1 Answers1

2

you just need to add #import "ReactNativeConfig.h" in bridging header. If you did that you can use it in your swift code without any additional import.

Here is some article I found helpful. https://medium.com/@subhangdxt/bridging-objective-c-and-swift-classes-5cb4139d9c80

And here is my code:

My app-Bridging-Header.h:

...
#import "ReactNativeConfig.h"
...

My AppDelegate.swift

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

  ...

  if let gmsApiKey = ReactNativeConfig.env(for: "GOOGLE_MAPS_API_KEY") {
    GMSServices.provideAPIKey(gmsApiKey)
  } else {
    print("ERROR: No goole maps api key provided!")
  }

  bridge = RCTBridge(delegate: self,  launchOptions: launchOptions)

  ...

  return true
}
adamvx
  • 157
  • 2
  • 10