Swift Beginner: Storyboardless Apps — I dropped storyboards and reused more Swift code and styles!
Six months ago while I was checking a Github repo, I realized that the repo didn’t have any Storyboard and all the design was defined in code.
First I thought that doing an app that way it was going to be a nightmare to visualize the UI and check designs, but also I saw the advantages, no more git conflicts when merging Storyboards, applying styles was going to be easier trough code, so I decided to give it a try.
The first thing to do is delete your main Storyboard for good! Then define in your AppDelegate
a new root controller:
In your project settings under Deployment Info, leave your Main Interface in blank:
With this steps done, your app will launch directly from code, in this case from MainViewController
When you leave behind Storyboards is necessary to use tools to do the layouts, I use SnapKit through CocoaPods to help me with the layouts.
Here is an example of the MainViewController
definition in code, take a look at the calls to snp.makeConstraints
method of SnapKit and the use of some Styles
using a simple Struct
to define Colors and Fonts
And the corresponding Styles:
So the big advantage is that I can reuse LoginViewControllers, SignUpViewControllers, About, Profile, etc… and just with changing the Styles.swift
definition got to reuse a lot of code through apps.-