visit
Note — The bridge can also serve images to the app by routing GET requests to an Images folder. However we don’t need to bother with this as our example will download the images instead.
ever-layout-bridge
in your project directory to start the server. It will by default look for a layouts directory ‘Layouts’ on port 3000
, but these options can be configured with arguments: ever-layout-bridge --layouts="MyLayouts” --port=”1234”
applicationDidLoad
.Note — It only really makes sense to connect to the bridge in DEBUG
mode, this isn’t something you want in production.
Double Note — Your HTTP server likely isn’t using an SSL certificate, which means we need to allow arbitrary connections for this to work. If you are unsure on how to do this, see this
connected
message in both the Xcode console, and the terminal window.ViewController.json
file in the Layouts directory.
import UIKit import EverLayout class ViewController: UIViewController { private var layout : EverLayout? override func viewDidLoad() { super.viewDidLoad() let layoutData = NSData(contentsOfFile: Bundle.main.path(forResource: "ViewController", ofType: "json", inDirectory: "Layouts")!) self.layout = EverLayout(layoutData: layoutData as! Data) self.layout?.buildLayout(onView: self.view, viewEnvironment: self) } }
buildLayout
call we are choosing to build the layout on the controller’s view, but using self
as a view environment. This is because the controller itself will contain properties that we will reference in our layout file.If your app is running and you’ve seen the connected
message, we can run a quick test to see if the layout updates are working.
ViewController.json
to look like the following and hit save.
This basic layout is applying an orange backgroundColor to its root
, which in our case in the controller’s view. Your app should look like this:
Now, let’s create a real layout:
EverLayout has found the text input and button views in the controller and applied a set a properties and layout constraints to them. However we didn’t have to create properties for the logo or even the input labels — they were described in the layout and EverLayout created them on the fly! We’re not likely going to need these properties for any logic, so why should we see them in our controller?