Last active
August 18, 2016 01:05
-
-
Save Bogidon/28435cc907197ae47aeee84b635c414b to your computer and use it in GitHub Desktop.
EasyStoryboards – a better way to manage storyboards and avoid merge conflicts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Storyboards.swift | |
// | |
// Created by Bogdan Vitoc on 7/5/16. | |
// Copyright © 2016 Bogdan Vitoc. All rights reserved. | |
// | |
// ⚠️ this is an example only | |
// ⚠️ modify the properties and strings to suit your project | |
import UIKit | |
struct ESBStoryboards { | |
static let onboarding = UIStoryboard(name: "Onboarding", bundle: nil) | |
static let login = UIStoryboard(name: "Login", bundle: nil) | |
static let home = UIStoryboard(name: "Home", bundle: nil) | |
static let settings = UIStoryboard(name: "Settings", bundle: nil) | |
static let example = UIStoryboard(name: "Example", bundle: nil) | |
// ... | |
static func storyBoardForClass<T>(type: T) -> UIStoryboard? { | |
switch type { | |
case is OnboardingViewController.Type: return onboarding | |
case is LoginViewControler.Type: return login | |
case is HomeViewController.Type: return home | |
case is SettingsViewController.Type: return settings | |
case is ExampleViewController.Type: return example | |
// ... | |
default: return nil | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ExampleViewController.swift | |
// | |
// Created by Bogdan Vitoc on 3/5/16. | |
// Copyright © 2016 Bogdan Vitoc. All rights reserved. | |
// | |
// ⚠️ this is an example only | |
import UIKit | |
class ExampleViewController: UIViewController, ESBViewControllerConventions { | |
@IBOutlet weak var aLabel: UILabel! | |
@IBOutlet weak var aButton: UIButton! | |
@IBOutlet weak var anImageView: UIImageView! | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// do things like | |
aLabel.text = "Hi" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// UIViewController+ESBConventions.swift | |
// | |
// Created by Bogdan Vitoc on 7/5/16. | |
// Copyright © 2016 Bogdan Vitoc. All rights reserved. | |
// | |
import UIKit | |
protocol ESBViewControllerConventions {} | |
extension ESBViewControllerConventions { | |
static func initFromStoryboard() -> Self? { | |
return ESBStoryboards.storyBoardForClass(Self)?.instantiateInitialViewController() as? Self | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Separate each view controller into it's own .storyboard file and use the name of that file in
ESBStoryboards.swift
. Also make that view controller the initial view controller of the storyboard.