diff --git a/docs/EmbeddedAppIOS.md b/docs/EmbeddedAppIOS.md index dbdb5e31d9c2c9..5bb036022c9573 100644 --- a/docs/EmbeddedAppIOS.md +++ b/docs/EmbeddedAppIOS.md @@ -118,6 +118,7 @@ In a view controller that wants to manage this view, go ahead and add an outlet @property (weak, nonatomic) IBOutlet ReactView *reactView; @end ``` +__NOTE__ For Swift apps there is no need for that. Here I disabled **AutoLayout** for simplicity. In real production world, you should turn on AutoLayout and setup constraints by yourself. @@ -149,6 +150,34 @@ Then add it as a subview of the `ReactView`. rootView.frame = self.bounds; ``` +### Swift apps + +Add the following to ReactView.swift file: + +``` +import UIKit +import React + +class ReactView: UIView { + + let rootView: RCTRootView = RCTRootView(bundleURL: NSURL(string: "http://localhost:8081/index.ios.bundle?platform=ios"), + moduleName: "SimpleApp", initialProperties: nil, launchOptions: nil) + + override func layoutSubviews() { + super.layoutSubviews() + + loadReact() + } + + func loadReact () { + addSubview(rootView) + rootView.frame = self.bounds + } +} +``` + +And then make sure your view is added in a ViewContainer or story board file. + ## Start Development Server In root directory, we need to start React Native development server.