Simple dependency injection for generating views from storyboard.

Overview

StoryboardBuilder

Simple dependency injection for generating views from storyboard.

Carthage Compatible Swift 4.2

Description

StoryboardBuilder is framework to help simply and easily generating that View and ViewController are defineded in Storyboard and Xib. You can generate instance and parse type of one by using StoryboardBuilderProtocol and XibBuilderProtocol description.

Install

Carthage

Add following.

github "hiro-nagami/StoryboardBuilder"

How ot use

Way to get Storyboard Class

  1. Create storyboard file in your project.

storyboard

  1. Import StoryboardBuilder_iOS.
  2. Your custom view controller extends StoryboardBuilderProtocol.
  3. storyboardName and storyboardID are implemented in that view controller.
import UIKit
import Foundation
import StoryboardBuilder_iOS

class CustomViewController: UIViewController, StoryboardBuilderProtocol {
    static var storyboardName: String = "Main"
    static var storyboardID: String = "CustomViewController"
    ...
}

You can use such as following.

/* You can generate CustomViewController just like following.
    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    let customeVC = storyboard.instantiateViewController(withIdentifier: "CustomViewController") as! CustomViewController
**/

let customViewController = CustomViewController.getModule()

Way to get Xib Class

  1. Create xib file in your project.

xib

  1. Import StoryboardBuilder_iOS.
  2. Your custom view controller extends XibBuilderProtocol.
  3. xibNameis implemented in that view controller.
import UIKit
import Foundation
import StoryboardBuilder_iOS

class CustomView: UIView, XibBuilderProtocol {
    static var xibName: String = "CustomView"
    ...
}

You can use such as following.

/* You can generate CustomView just like following.
   let identifier = "CustomView"
   let customViewNib = UINib(nibName: identifier, bundle: nil)
   let customView = customViewNib.instantiate(withOwner: self, options: nil).first as! CustomView
**/

let customView: CustomView = CustomView.getModule()

You can register and use CustomTableViewCell.

class CustomViewCell: UITableViewCell, XibBuilderProtocol {
    static var xibName: String = "CustomView"
    ...
}

class TableViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
    @IBOutlet weak var tableView: UITableView!

    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.tableView.delegate = self
        self.tableView.dataSource = self
        self.tableView.sb.register(cellClass: CustomViewCell.self)
        self.tableView.sb.register(cellClasses: [
            CustomViewACell.self,
            CustomViewBCell.self,
            CustomViewCCell.self,
        ])
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.sb.dequeueReusableCell(cellClass: CustomViewBCell.self)

        ...
        
        return cell
    }
}

License

StoryboardBuilder is released under the MIT license. See LICENSE for details.

Author

@hiro_nagami

You might also like...
A Simple way help you drop or drag your source (like UIImage) between different App.

A Simple way help you drop or drag your source (like UIImage) between different App.

A simple protocol package that does nothing

HasResult A simple protocol package that does nothing. The HasResult protocol has a simple result property and a ResultType associated type. This is m

A simple Hacker News mobile client

A simple Hacker News mobile client. Overview This app was built with the Hacker News API This is one of my first apps outside of a tut

A simple Swift sample code to reads ISO 10303-21 exchange structure (STEP P21) file for AP242 schema.

simpleP21ReadSample A simple sample code to reads ISO 10303-21 exchange structure (STEP P21) file for AP242 schema. by Tsutomu Yoshida, Minokamo Japan

A simple, reliable and scalable delivery API for transactional push notifications for websites and applications
A simple, reliable and scalable delivery API for transactional push notifications for websites and applications

Catapush is a simple, reliable and scalable delivery API for transactional push notifications for websites and applications. Ideal for sending data-dr

Eval for Swift - Easily evaluate simple expressions on the go

Eval for Swift Easily evaluate simple expressions on the go... This is a port of the BigEval.js/Eval.net library Features: Evaluate basic math operato

A simple To Do application written in React Native

Example To Do List application in react-native Requirements, install as needed: React Native: $ npm i -g react-native-cli watchman: $ brew install wa

RMSUI - A Simple Swift MVVM architectured Rick & Morty UI app in order to practice SwiftUI & GraphQL

RMSUI A Simple Swift MVVM architectured "Rick & Morty UI" app 📲 in order to pra

Tofu - A simple Todo app built with SwiftUI, a REST API, and a local Realm cache
Tofu - A simple Todo app built with SwiftUI, a REST API, and a local Realm cache

Tofu A simple Todo app built with SwiftUI, a REST API, and a local Realm cache.

Owner
null
swumap swift storyboard project

swumap swift storyboard project

jojjoeeeeeee 0 Oct 20, 2021
Mimicrated views and controls to native Apple appearance.

Mimicrated views and controls to native Apple appearance. If you have any ideas of what elements can be added, let me know. Below you will see previews of all the elements and how to use them.

Ivan Vorobei 85 Dec 3, 2022
Easy-to-use segues in SwiftUI, allowing for presenting views using common UIKIt Segue types - push, modal and popover

Easy-to-use segues in SwiftUI, allowing for presenting views using common UIKIt Segue types - push, modal and popover

Gordan Glavaš 5 Apr 16, 2022
Goal: Create an iOS app with two views, MainViewController and DetailViewController

Goal: Create an iOS app with two views, MainViewController and DetailViewController

Jesse Rae 0 Jan 23, 2022
A simple project which shows how to pull off custom view controller transitions.

Custom View Controller Transitions This project explains and shows how to make custom view controller transitions in the most simple way possible. Eac

Jordan Morgan 91 Oct 23, 2022
A simple deamon that restores your window positions on external monitors.

Memmon Memmon remembers what your Mac forgets – A simple deamon that restores your window positions on external monitors. FAQ Why‽ I am frustrated! Wh

Helena Schobs 55 Dec 1, 2022
A simple project that shows a list of local coffee shop reviews

Project This is a simple project that shows a list of local coffee shop reviews Details Please use git and commit often with meaningful commit message

null 0 Oct 16, 2021
This is a simple mobile app which is connect to the Twitter API

Project 3 - My Twitter My Twitter is a basic twitter app to read your tweets. Time spent on two parts: 8.5 hours spent in total Twitter - Part II This

Alem 1 Dec 14, 2022
A simple self-development challenge application that aimed to learn

Movie List Challenge A simple self-development challenge application that aimed to learn "The Composable Architecture" basics and build a reactive str

Nicat Muzaffarli 1 Oct 30, 2021
Simple Background Fetch Tasks

Simple Background Fetch Tasks

samrez Ikram 0 Oct 30, 2021