Skip to content

DKalachniuk/SwiftyStoryboard

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 

Repository files navigation

SwiftyStoryboard

A More Swifty way to use storyboards

Carthage compatible

##Motivation: Take a look at the code below:

let storyboard = UIStoryboard(name: "Main", bundle: nil)
let controller = storyboard.instantiateViewControllerWithIdentifier("Settings") as! SettingsViewController

Such code has 2 disadvantages:

  • Storyboard name is raw string
  • Controller identifier is raw string

We want to get rid of that. SwiftyStoryboard allows to deal with both of there problems in one shot.

##Usage example We create a struct that conforms to Storyboard protocol like this one:

struct Main: Storyboard {
    enum ControllerId: String {
        case Settings
    }
}

and now we can instantiate out controller with specific identifier like this:

let controller: SettingsViewController = Main.instantiateViewController(with: .Settings)

Such approach allows us to distinguish different storyboards with different controller identifiers and give more information to compiler about our storyboards.

SwiftyStoryboard by deafult take the the type name as the name of the storyboard file. For example, in this case it will take Main.storyboard as the name of the type is Main

About

A more Swifty way to use storyboards

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Swift 83.6%
  • Objective-C 16.4%