From 580d06168225c46c13a555080a310d734b0588b7 Mon Sep 17 00:00:00 2001 From: Zane Campbell Date: Thu, 22 Sep 2016 15:16:44 -0400 Subject: [PATCH] - updated to work with Swift 3 --- AHStoryboard/AHStoryboard.xcodeproj/project.pbxproj | 3 +++ .../Extension/UIStoryboard+Storyboards.swift | 11 +++++------ .../Protocol/StoryboardIdentifiable.swift | 4 ++-- README.md | 2 +- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/AHStoryboard/AHStoryboard.xcodeproj/project.pbxproj b/AHStoryboard/AHStoryboard.xcodeproj/project.pbxproj index b9c4639..ab12146 100644 --- a/AHStoryboard/AHStoryboard.xcodeproj/project.pbxproj +++ b/AHStoryboard/AHStoryboard.xcodeproj/project.pbxproj @@ -146,6 +146,7 @@ TargetAttributes = { 666256841C4E35E300081F62 = { CreatedOnToolsVersion = 7.2; + LastSwiftMigration = 0800; }; }; }; @@ -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; }; @@ -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; }; diff --git a/AHStoryboard/AHStoryboard/Extension/UIStoryboard+Storyboards.swift b/AHStoryboard/AHStoryboard/Extension/UIStoryboard+Storyboards.swift index 310d76c..7f35feb 100644 --- a/AHStoryboard/AHStoryboard/Extension/UIStoryboard+Storyboards.swift +++ b/AHStoryboard/AHStoryboard/Extension/UIStoryboard+Storyboards.swift @@ -17,18 +17,18 @@ 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) } @@ -36,7 +36,7 @@ extension UIStoryboard { /// View Controller Instantiation from Generics /// Old Way: - func instantiateViewController(_: T.Type) -> T { + func instantiateViewController(_: 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) ") } @@ -45,7 +45,7 @@ extension UIStoryboard { } /// New Way - func instantiateViewController() -> T { + func instantiateViewController() -> T where T: StoryboardIdentifiable { guard let viewController = self.instantiateViewControllerWithIdentifier(T.storyboardIdentifier) as? T else { fatalError("Couldn't instantiate view controller with identifier \(T.storyboardIdentifier) ") } @@ -53,4 +53,3 @@ extension UIStoryboard { return viewController } } - diff --git a/AHStoryboard/AHStoryboard/Protocol/StoryboardIdentifiable.swift b/AHStoryboard/AHStoryboard/Protocol/StoryboardIdentifiable.swift index db5b6c7..1bc7851 100644 --- a/AHStoryboard/AHStoryboard/Protocol/StoryboardIdentifiable.swift +++ b/AHStoryboard/AHStoryboard/Protocol/StoryboardIdentifiable.swift @@ -14,6 +14,6 @@ protocol StoryboardIdentifiable { extension StoryboardIdentifiable where Self: UIViewController { static var storyboardIdentifier: String { - return String(self) + return String(describing: self) } -} \ No newline at end of file +} diff --git a/README.md b/README.md index e11cf58..fd86446 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ Into this: ```` let storyboard = UIStoryboard.storyboard(.News) -let viewController = storyboard.instantiateViewController(ArticleViewController.self) +let viewController: ArticleViewController = storyboard.instantiateViewController() viewController.printHeadline() ````