Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions AHStoryboard/AHStoryboard.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@
TargetAttributes = {
666256841C4E35E300081F62 = {
CreatedOnToolsVersion = 7.2;
LastSwiftMigration = 0800;
};
};
};
Expand Down Expand Up @@ -307,6 +308,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.AndyyHope.AHStoryboard;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand All @@ -318,6 +320,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.AndyyHope.AHStoryboard;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,26 @@ extension UIStoryboard {
case News
case Gallery
}

/// Convenience Initializers

convenience init(storyboard: Storyboard, bundle: NSBundle? = nil) {
convenience init(storyboard: Storyboard, bundle: Bundle? = nil) {
self.init(name: storyboard.rawValue, bundle: bundle)
}


/// Class Functions

class func storyboard(storyboard: Storyboard, bundle: NSBundle? = nil) -> UIStoryboard {
class func storyboard(storyboard: Storyboard, bundle: Bundle? = nil) -> UIStoryboard {
return UIStoryboard(name: storyboard.rawValue, bundle: bundle)
}


/// View Controller Instantiation from Generics
/// Old Way:

func instantiateViewController<T: UIViewController where T: StoryboardIdentifiable>(_: T.Type) -> T {
func instantiateViewController<T: UIViewController>(_: T.Type) -> T where T: StoryboardIdentifiable {
guard let viewController = self.instantiateViewControllerWithIdentifier(T.storyboardIdentifier) as? T else {
fatalError("Couldn't instantiate view controller with identifier \(T.storyboardIdentifier) ")
}
Expand All @@ -45,12 +45,11 @@ extension UIStoryboard {
}

/// New Way
func instantiateViewController<T: UIViewController where T: StoryboardIdentifiable>() -> T {
func instantiateViewController<T: UIViewController>() -> T where T: StoryboardIdentifiable {
guard let viewController = self.instantiateViewControllerWithIdentifier(T.storyboardIdentifier) as? T else {
fatalError("Couldn't instantiate view controller with identifier \(T.storyboardIdentifier) ")
}

return viewController
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ protocol StoryboardIdentifiable {

extension StoryboardIdentifiable where Self: UIViewController {
static var storyboardIdentifier: String {
return String(self)
return String(describing: self)
}
}
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Into this:
````
let storyboard = UIStoryboard.storyboard(.News)

let viewController = storyboard.instantiateViewController(ArticleViewController.self)
let viewController: ArticleViewController = storyboard.instantiateViewController()

viewController.printHeadline()
````
Expand Down