Last active
September 30, 2016 11:10
-
-
Save markcleonard/f1a19b27c00f8e1c82872705c1a06863 to your computer and use it in GitHub Desktop.
Revisions
-
markcleonard revised this gist
Sep 30, 2016 . 1 changed file with 18 additions and 9 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -2,9 +2,9 @@ import UIKit enum Storyboard: String { case main = "Main" case history = "History" case more = "More" func storyboard() -> UIStoryboard { return UIStoryboard(name: rawValue, bundle: nil) @@ -14,9 +14,7 @@ enum Storyboard: String { protocol StoryboardCreatable { associatedtype ViewModel static var storyboard: Storyboard { get } var viewModel: ViewModel { get set } } extension StoryboardCreatable { @@ -47,19 +45,30 @@ extension UIStoryboard { } } // MARK: Implementation struct User { let name: String } struct History { } struct HistoryViewModel { let user: User let history: History } final class HistoryViewController: UIViewController, StoryboardCreatable { static var storyboard: Storyboard = .history var viewModel: HistoryViewModel! @IBOutlet weak var label: UILabel! override func viewDidLoad() { super.viewDidLoad() label.text = viewModel.user.name } } let viewModel = HistoryViewModel(user: User(name: "Mark"), history: History()) let viewController = HistoryViewController.createFromStoryboard(viewModel: viewModel) -
markcleonard revised this gist
Sep 29, 2016 . 1 changed file with 6 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -21,7 +21,7 @@ protocol StoryboardCreatable { extension StoryboardCreatable { static var storyboardIdentifier: String { return String(describing: Self.self) } mutating func configureWithViewModel(viewModel: ViewModel) { self.viewModel = viewModel @@ -31,15 +31,15 @@ extension StoryboardCreatable { extension StoryboardCreatable where Self: UIViewController { static func createFromStoryboard(viewModel: ViewModel) -> Self { var viewController: Self = UIStoryboard.createViewController() viewController.configureWithViewModel(viewModel: viewModel) return viewController } } extension UIStoryboard { static func createViewController<T: StoryboardCreatable>() -> T { let storyboard = UIStoryboard(name: T.storyboard.rawValue, bundle: nil) let createViewController = storyboard.instantiateViewController(withIdentifier: T.storyboardIdentifier) guard createViewController is T else { fatalError("Expected view controller with identifier \(T.storyboardIdentifier)") } @@ -59,5 +59,7 @@ struct HistoryViewModel { final class HistoryViewController: UIViewController, StoryboardCreatable { static var storyboard: Storyboard = .History var viewModel: HistoryViewModel! } let viewModel = HistoryViewModel(user: User(), history: History()) let viewController = HistoryViewController.createFromStoryboard(viewModel: viewModel) -
markcleonard revised this gist
Sep 29, 2016 . 1 changed file with 0 additions and 9 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,12 +1,3 @@ import UIKit -
markcleonard revised this gist
Sep 29, 2016 . 1 changed file with 43 additions and 29 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,58 +1,72 @@ import UIKit // // Storyboard.swift // PokerMate // // Created by Mark Leonard on 8/7/16. // // import UIKit enum Storyboard: String { case Main case History case More func storyboard() -> UIStoryboard { return UIStoryboard(name: rawValue, bundle: nil) } } protocol StoryboardCreatable { associatedtype ViewModel static var storyboard: Storyboard { get } static var storyboardIdentifier: String { get } var viewModel: ViewModel { get set } mutating func configureWithViewModel(viewModel: ViewModel) } extension StoryboardCreatable { static var storyboardIdentifier: String { return String(Self) } mutating func configureWithViewModel(viewModel: ViewModel) { self.viewModel = viewModel } } extension StoryboardCreatable where Self: UIViewController { static func createFromStoryboard(viewModel: ViewModel) -> Self { var viewController: Self = UIStoryboard.createViewController() viewController.configureWithViewModel(viewModel) return viewController } } extension UIStoryboard { static func createViewController<T: StoryboardCreatable>() -> T { let storyboard = UIStoryboard(name: T.storyboard.rawValue, bundle: nil) let createViewController = storyboard.instantiateViewControllerWithIdentifier(T.storyboardIdentifier) guard createViewController is T else { fatalError("Expected view controller with identifier \(T.storyboardIdentifier)") } return createViewController as! T } } struct User { } struct History { } struct HistoryViewModel { let user: User let history: History } //MARK: Implementation final class HistoryViewController: UIViewController, StoryboardCreatable { static var storyboard: Storyboard = .History var viewModel: HistoryViewModel! } -
markcleonard created this gist
Sep 25, 2016 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,58 @@ import UIKit // MARK: Logic protocol StoryboardCreatable { associatedtype Dependencies static var storyboard: Storyboard { get } static var storyboardIdentifier: String { get } static func createFromStoryboard(dependencies: Dependencies) -> Self func configure(dependencies: Dependencies) } extension StoryboardCreatable where Self: UIViewController { static func createFromStoryboard(dependencies: Dependencies) -> Self { let viewController: Self = UIStoryboard.createViewController() viewController.configure(dependencies: dependencies) return viewController } } extension UIStoryboard { static func createViewController<T: StoryboardCreatable>() -> T { let storyboard = UIStoryboard(name: T.storyboard.rawValue, bundle: nil) let createViewController = storyboard.instantiateViewController(withIdentifier: T.storyboardIdentifier) guard createViewController is T else { fatalError("Expected view controller with identifier \(T.storyboardIdentifier)") } return createViewController as! T } } //MARK: Model enum Storyboard: String { case Main = "Main" case History = "History" case More = "More" func storyboard() -> UIStoryboard { return UIStoryboard(name: rawValue, bundle: nil) } } struct User { } struct History { } //MARK: Implementation final class HistoryViewController: UIViewController, StoryboardCreatable { static var storyboard = Storyboard.History static var storyboardIdentifier = "HistoryViewController" typealias Dependencies = (user: User, history: History) func configure(dependencies: Dependencies) { history = dependencies.history user = dependencies.user } private var user: User! private var history: History! }