Skip to content

Instantly share code, notes, and snippets.

@justinmakaila
Created November 20, 2017 18:19
Show Gist options
  • Save justinmakaila/42773a50c1aa86d03e6c1b3536042280 to your computer and use it in GitHub Desktop.
Save justinmakaila/42773a50c1aa86d03e6c1b3536042280 to your computer and use it in GitHub Desktop.
React Native App Delegate in Swift 4.0
import UIKit
let CodeLocation = "index"
let ModuleName = "<ProjectName>"
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil
) -> Bool {
guard let codeLocation = RCTBundleURLProvider.sharedSettings().jsBundleURL(
forBundleRoot: CodeLocation,
fallbackResource: nil
),
let rootView = RCTRootView(
bundleURL: codeLocation,
moduleName: ModuleName,
initialProperties: nil,
launchOptions: launchOptions
)
else {
return false
}
let rootViewController = UIViewController()
rootViewController.view = rootView
self.window = UIWindow(frame: UIScreen.main.bounds)
self.window?.rootViewController = rootViewController
self.window?.makeKeyAndVisible()
return true
}
}
@justinmakaila
Copy link
Author

Add a bridging header to the project with these contents:

//
//  Use this file to import your target's public headers that you would like to expose to Swift.
//

#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
/// ... Any other React libraries that you need to access in Swift

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment