andyyhope / Blog_UIStoryboardSafety

Example code for a blog post i wrote on Medium

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

UIStoryboard: Safer with Enums, Protocol Extensions and Generics

Because String literals are so yucky.

Medium post

UIStoryboard: Safer with Enums, Protocol Extensions and Generics

tl;dr

Turn this:

let name = "News"

let storyboard = UIStoryboard(name: name, bundle: nil)

let identifier = "ArticleViewController"

let viewController = storyboard.instantiateViewControllerWithIdentifier(identifier) as! ArticleViewController

viewController.printHeadline()

Into this:

let storyboard = UIStoryboard.storyboard(.News)

let viewController = storyboard.instantiateViewController(ArticleViewController.self)

viewController.printHeadline()

About

Example code for a blog post i wrote on Medium

License:MIT License


Languages

Language:Swift 100.0%