Latest 1.0.2
Homepage https://github.com/YuriFox/UIStoryboardReference
License MIT
Platforms ios 8.0
Authors

[platform]()
[language]()
[language]()
[license]()

Requirements

  • iOS 8.0+
  • Xcode 9.0+
  • Swift 4.0+

Installation

Cocoa pods

To integrate UIStoryboardReference into your Xcode project using CocoaPods, create Podfile. Run the following command in root folder of your project:

$ pod init

In the Podfile that appears, specify:

platform :ios, ‘8.0’

target '<Your Target Name>' do
    use_frameworks!
    pod 'UIStoryboardReference'
end

Then, run the following command:

$ pod install

Usage

Create storyboard instance

First of all you must use UIStoryboardFilename protocol for create safe storyboard instance. The easiest way is create enum.

/// The safe name of the storyboard resource.
enum MyProjectStoryboard: String, UIStoryboardFilename {

    /// Login.storyboard filename
    case login

    /// Main.storybard filename
    case main

    /// The safe name of the storyboard resource without extension. For exmple for `Main.story` file you need get only name `Main`.
    var storyboardFilename: String { 
        return self.rawValue.capitalized
    }

}

You can create new instance of UIStoryboard from UIStoryboardName.

// Create `Login.storyboard` instance
let loginStoryboard = UIStoryboard(MyProjectStoryboard.login)

// Create `Main.storyboard` instance
let mainStoryboard = UIStoryboard(MyProjectStoryboard.main)

Get instantiateInitialViewController

You can get storyboard instantiateInitialViewController with force casting to selected type.

let storyboard = UIStoryboard(MyProjectStoryboard.main)

let initialViewController_0 = storyboard.initialViewController(UINavigationController.self)  

// It's the same way to get initialViewController as `initialViewController_0` but have different syntaxis. Use which is more suitable for you
let initialViewController_1: UINavigationController = storyboard.initialViewController() 

Get instantiateViewController

You can get storyboard instantiateViewController with storyboard identefier value storyboardReferenceIdentefier and force casting to selected type.

let viewController_0 = storyboard.viewController(UITableViewController.self)

// It's the same way to get viewController as `viewController_0` but have different syntaxis. Use which is more suitable for you
let viewController_1: UITableViewController = storyboard.viewController()

Attention! If viewController can’t cast to selected type or storyboard don’t have view controller with identefier you fetch fatal error!

License

Released under the MIT license. See LICENSE for details.

Latest podspec

{
    "name": "UIStoryboardReference",
    "version": "1.0.2",
    "summary": "UIStoryboard safe reference",
    "description": "Easy and safe way to deal with UIStoryboard",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "YuriFox": "[email protected]"
    },
    "platforms": {
        "ios": "8.0"
    },
    "homepage": "https://github.com/YuriFox/UIStoryboardReference",
    "source": {
        "git": "https://github.com/YuriFox/UIStoryboardReference.git",
        "tag": "1.0.2"
    },
    "source_files": "Source/*.swift"
}

Pin It on Pinterest

Share This