|
| 1 | +// |
| 2 | +// Autogenerated by Natalie - Storyboard Generator |
| 3 | +// by Marcin Krzyzanowski http://krzyzanowskim.com |
| 4 | +// |
| 5 | +import UIKit |
| 6 | + |
| 7 | +// MARK: - Storyboards |
| 8 | + |
| 9 | +extension UIStoryboard { |
| 10 | + func instantiateViewController<T: UIViewController>(ofType type: T.Type) -> T? where T: IdentifiableProtocol { |
| 11 | + let instance = type.init() |
| 12 | + if let identifier = instance.storyboardIdentifier { |
| 13 | + return self.instantiateViewController(withIdentifier: identifier) as? T |
| 14 | + } |
| 15 | + return nil |
| 16 | + } |
| 17 | + |
| 18 | +} |
| 19 | + |
| 20 | +protocol Storyboard { |
| 21 | + static var storyboard: UIStoryboard { get } |
| 22 | + static var identifier: String { get } |
| 23 | +} |
| 24 | + |
| 25 | +struct Storyboards { |
| 26 | + |
| 27 | + struct Login: Storyboard { |
| 28 | + |
| 29 | + static let identifier = "Login" |
| 30 | + |
| 31 | + static var storyboard: UIStoryboard { |
| 32 | + return UIStoryboard(name: self.identifier, bundle: nil) |
| 33 | + } |
| 34 | + |
| 35 | + static func instantiateViewController(withIdentifier identifier: String) -> UIViewController { |
| 36 | + return self.storyboard.instantiateViewController(withIdentifier: identifier) |
| 37 | + } |
| 38 | + |
| 39 | + static func instantiateViewController<T: UIViewController>(ofType type: T.Type) -> T? where T: IdentifiableProtocol { |
| 40 | + return self.storyboard.instantiateViewController(ofType: type) |
| 41 | + } |
| 42 | + |
| 43 | + static func instantiateLoginViewController() -> LoginViewController { |
| 44 | + return self.storyboard.instantiateViewController(withIdentifier: "LoginViewController") as! LoginViewController |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + struct LaunchScreen: Storyboard { |
| 49 | + |
| 50 | + static let identifier = "LaunchScreen" |
| 51 | + |
| 52 | + static var storyboard: UIStoryboard { |
| 53 | + return UIStoryboard(name: self.identifier, bundle: nil) |
| 54 | + } |
| 55 | + |
| 56 | + static func instantiateInitialViewController() -> UIViewController { |
| 57 | + return self.storyboard.instantiateInitialViewController()! |
| 58 | + } |
| 59 | + |
| 60 | + static func instantiateViewController(withIdentifier identifier: String) -> UIViewController { |
| 61 | + return self.storyboard.instantiateViewController(withIdentifier: identifier) |
| 62 | + } |
| 63 | + |
| 64 | + static func instantiateViewController<T: UIViewController>(ofType type: T.Type) -> T? where T: IdentifiableProtocol { |
| 65 | + return self.storyboard.instantiateViewController(ofType: type) |
| 66 | + } |
| 67 | + } |
| 68 | + |
| 69 | + struct Main: Storyboard { |
| 70 | + |
| 71 | + static let identifier = "Main" |
| 72 | + |
| 73 | + static var storyboard: UIStoryboard { |
| 74 | + return UIStoryboard(name: self.identifier, bundle: nil) |
| 75 | + } |
| 76 | + |
| 77 | + static func instantiateInitialViewController() -> UITabBarController { |
| 78 | + return self.storyboard.instantiateInitialViewController() as! UITabBarController |
| 79 | + } |
| 80 | + |
| 81 | + static func instantiateViewController(withIdentifier identifier: String) -> UIViewController { |
| 82 | + return self.storyboard.instantiateViewController(withIdentifier: identifier) |
| 83 | + } |
| 84 | + |
| 85 | + static func instantiateViewController<T: UIViewController>(ofType type: T.Type) -> T? where T: IdentifiableProtocol { |
| 86 | + return self.storyboard.instantiateViewController(ofType: type) |
| 87 | + } |
| 88 | + } |
| 89 | +} |
| 90 | + |
| 91 | +// MARK: - ReusableKind |
| 92 | +enum ReusableKind: String, CustomStringConvertible { |
| 93 | + case tableViewCell = "tableViewCell" |
| 94 | + case collectionViewCell = "collectionViewCell" |
| 95 | + |
| 96 | + var description: String { return self.rawValue } |
| 97 | +} |
| 98 | + |
| 99 | +// MARK: - SegueKind |
| 100 | +enum SegueKind: String, CustomStringConvertible { |
| 101 | + case relationship = "relationship" |
| 102 | + case show = "show" |
| 103 | + case presentation = "presentation" |
| 104 | + case embed = "embed" |
| 105 | + case unwind = "unwind" |
| 106 | + case push = "push" |
| 107 | + case modal = "modal" |
| 108 | + case popover = "popover" |
| 109 | + case replace = "replace" |
| 110 | + case custom = "custom" |
| 111 | + |
| 112 | + var description: String { return self.rawValue } |
| 113 | +} |
| 114 | + |
| 115 | +// MARK: - IdentifiableProtocol |
| 116 | + |
| 117 | +public protocol IdentifiableProtocol: Equatable { |
| 118 | + var storyboardIdentifier: String? { get } |
| 119 | +} |
| 120 | + |
| 121 | +// MARK: - SegueProtocol |
| 122 | + |
| 123 | +public protocol SegueProtocol { |
| 124 | + var identifier: String? { get } |
| 125 | +} |
| 126 | + |
| 127 | +public func ==<T: SegueProtocol, U: SegueProtocol>(lhs: T, rhs: U) -> Bool { |
| 128 | + return lhs.identifier == rhs.identifier |
| 129 | +} |
| 130 | + |
| 131 | +public func ~=<T: SegueProtocol, U: SegueProtocol>(lhs: T, rhs: U) -> Bool { |
| 132 | + return lhs.identifier == rhs.identifier |
| 133 | +} |
| 134 | + |
| 135 | +public func ==<T: SegueProtocol>(lhs: T, rhs: String) -> Bool { |
| 136 | + return lhs.identifier == rhs |
| 137 | +} |
| 138 | + |
| 139 | +public func ~=<T: SegueProtocol>(lhs: T, rhs: String) -> Bool { |
| 140 | + return lhs.identifier == rhs |
| 141 | +} |
| 142 | + |
| 143 | +public func ==<T: SegueProtocol>(lhs: String, rhs: T) -> Bool { |
| 144 | + return lhs == rhs.identifier |
| 145 | +} |
| 146 | + |
| 147 | +public func ~=<T: SegueProtocol>(lhs: String, rhs: T) -> Bool { |
| 148 | + return lhs == rhs.identifier |
| 149 | +} |
| 150 | + |
| 151 | +// MARK: - ReusableViewProtocol |
| 152 | +public protocol ReusableViewProtocol: IdentifiableProtocol { |
| 153 | + var viewType: UIView.Type? { get } |
| 154 | +} |
| 155 | + |
| 156 | +public func ==<T: ReusableViewProtocol, U: ReusableViewProtocol>(lhs: T, rhs: U) -> Bool { |
| 157 | + return lhs.storyboardIdentifier == rhs.storyboardIdentifier |
| 158 | +} |
| 159 | + |
| 160 | +// MARK: - Protocol Implementation |
| 161 | +extension UIStoryboardSegue: SegueProtocol { |
| 162 | +} |
| 163 | + |
| 164 | +extension UICollectionReusableView: ReusableViewProtocol { |
| 165 | + public var viewType: UIView.Type? { return type(of: self) } |
| 166 | + public var storyboardIdentifier: String? { return self.reuseIdentifier } |
| 167 | +} |
| 168 | + |
| 169 | +extension UITableViewCell: ReusableViewProtocol { |
| 170 | + public var viewType: UIView.Type? { return type(of: self) } |
| 171 | + public var storyboardIdentifier: String? { return self.reuseIdentifier } |
| 172 | +} |
| 173 | + |
| 174 | +// MARK: - UIViewController extension |
| 175 | +extension UIViewController { |
| 176 | + func perform<T: SegueProtocol>(segue: T, sender: Any?) { |
| 177 | + if let identifier = segue.identifier { |
| 178 | + performSegue(withIdentifier: identifier, sender: sender) |
| 179 | + } |
| 180 | + } |
| 181 | + |
| 182 | + func perform<T: SegueProtocol>(segue: T) { |
| 183 | + perform(segue: segue, sender: nil) |
| 184 | + } |
| 185 | +} |
| 186 | +// MARK: - UICollectionView |
| 187 | + |
| 188 | +extension UICollectionView { |
| 189 | + |
| 190 | + func dequeue<T: ReusableViewProtocol>(reusable: T, for: IndexPath) -> UICollectionViewCell? { |
| 191 | + if let identifier = reusable.storyboardIdentifier { |
| 192 | + return dequeueReusableCell(withReuseIdentifier: identifier, for: `for`) |
| 193 | + } |
| 194 | + return nil |
| 195 | + } |
| 196 | + |
| 197 | + func register<T: ReusableViewProtocol>(reusable: T) { |
| 198 | + if let type = reusable.viewType, let identifier = reusable.storyboardIdentifier { |
| 199 | + register(type, forCellWithReuseIdentifier: identifier) |
| 200 | + } |
| 201 | + } |
| 202 | + |
| 203 | + func dequeueReusableSupplementaryViewOfKind<T: ReusableViewProtocol>(elementKind: String, withReusable reusable: T, for: IndexPath) -> UICollectionReusableView? { |
| 204 | + if let identifier = reusable.storyboardIdentifier { |
| 205 | + return dequeueReusableSupplementaryView(ofKind: elementKind, withReuseIdentifier: identifier, for: `for`) |
| 206 | + } |
| 207 | + return nil |
| 208 | + } |
| 209 | + |
| 210 | + func register<T: ReusableViewProtocol>(reusable: T, forSupplementaryViewOfKind elementKind: String) { |
| 211 | + if let type = reusable.viewType, let identifier = reusable.storyboardIdentifier { |
| 212 | + register(type, forSupplementaryViewOfKind: elementKind, withReuseIdentifier: identifier) |
| 213 | + } |
| 214 | + } |
| 215 | +} |
| 216 | +// MARK: - UITableView |
| 217 | + |
| 218 | +extension UITableView { |
| 219 | + |
| 220 | + func dequeue<T: ReusableViewProtocol>(reusable: T, for: IndexPath) -> UITableViewCell? { |
| 221 | + if let identifier = reusable.storyboardIdentifier { |
| 222 | + return dequeueReusableCell(withIdentifier: identifier, for: `for`) |
| 223 | + } |
| 224 | + return nil |
| 225 | + } |
| 226 | + |
| 227 | + func register<T: ReusableViewProtocol>(reusable: T) { |
| 228 | + if let type = reusable.viewType, let identifier = reusable.storyboardIdentifier { |
| 229 | + register(type, forCellReuseIdentifier: identifier) |
| 230 | + } |
| 231 | + } |
| 232 | + |
| 233 | + func dequeueReusableHeaderFooter<T: ReusableViewProtocol>(_ reusable: T) -> UITableViewHeaderFooterView? { |
| 234 | + if let identifier = reusable.storyboardIdentifier { |
| 235 | + return dequeueReusableHeaderFooterView(withIdentifier: identifier) |
| 236 | + } |
| 237 | + return nil |
| 238 | + } |
| 239 | + |
| 240 | + func registerReusableHeaderFooter<T: ReusableViewProtocol>(_ reusable: T) { |
| 241 | + if let type = reusable.viewType, let identifier = reusable.storyboardIdentifier { |
| 242 | + register(type, forHeaderFooterViewReuseIdentifier: identifier) |
| 243 | + } |
| 244 | + } |
| 245 | +} |
| 246 | + |
| 247 | +// MARK: - LoginViewController |
| 248 | +protocol LoginViewControllerIdentifiableProtocol: IdentifiableProtocol { } |
| 249 | + |
| 250 | +extension LoginViewController: LoginViewControllerIdentifiableProtocol { } |
| 251 | + |
| 252 | +extension IdentifiableProtocol where Self: LoginViewController { |
| 253 | + var storyboardIdentifier: String? { return "LoginViewController" } |
| 254 | + static var storyboardIdentifier: String? { return "LoginViewController" } |
| 255 | +} |
| 256 | + |
0 commit comments