Last active
          August 25, 2020 13:31 
        
      - 
      
- 
        Save KalpeshTalkar/b0876a55fe049e96bc38a02fc7b74c04 to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | // | |
| // Copyright © 2017 Kalpesh Talkar. All rights reserved. | |
| // | |
| // Licensed under the Apache License, Version 2.0 (the "License"); | |
| // you may not use this file except in compliance with the License. | |
| // You may obtain a copy of the License at | |
| // | |
| // http://www.apache.org/licenses/LICENSE-2.0 | |
| // | |
| // Unless required by applicable law or agreed to in writing, software | |
| // distributed under the License is distributed on an "AS IS" BASIS, | |
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| // See the License for the specific language governing permissions and | |
| // limitations under the License. | |
| // | |
| // For support: https://gist.github.com/KalpeshTalkar/b0876a55fe049e96bc38a02fc7b74c04 | |
| // | |
| import UIKit | |
| extension UIStoryboard { | |
| /// Get UIViewController instance with the identifier | |
| /// | |
| /// - parameter identifier: id of the view controller given in storyboard | |
| /// | |
| /// - returns: new instance of UIViewController with the provided id | |
| func viewController(for identifier: String) -> UIViewController { | |
| return self.instantiateViewController(withIdentifier: identifier) | |
| } | |
| /// Get type casted UIViewController instance with the identifier | |
| /// | |
| /// - parameter type: type of the UIViewController | |
| /// - parameter identifier: id of the view controller given in storyboard (make sure the view controller has the identifier set in the storyboard) | |
| /// | |
| /// - returns: new instance of UIViewController with the provided id | |
| func viewController<T: UIViewController>(of type: T.Type, for identifier: String? = nil) -> T? { | |
| return self.instantiateViewController(withIdentifier: identifier ?? String(describing: T.self)) as? T | |
| } | |
| } | |
| struct Storyboard { | |
| static let Main = UIStoryboard(name: "Main", bundle: nil) | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
Usage: