Skip to content

Instantly share code, notes, and snippets.

@leilee
Created September 19, 2016 03:06
Show Gist options
  • Select an option

  • Save leilee/c6dd6e46f426031dc30fa5ff3042df62 to your computer and use it in GitHub Desktop.

Select an option

Save leilee/c6dd6e46f426031dc30fa5ff3042df62 to your computer and use it in GitHub Desktop.
// MARK: - Load View From `.xib`
extension UINib {
enum Nib: String {
case SettingHeaderView
case FreeAccountFeaturesView
case ProAccountFeaturesView
case EnterpriseAccountFeaturesView
}
convenience init(nib: Nib, bundle: NSBundle? = nil) {
self.init(nibName: nib.rawValue, bundle: bundle)
}
class func nib(nib: Nib, bundle: NSBundle? = nil) -> UINib {
return UINib(nib: nib, bundle: bundle)
}
func instantiateView<T: UIView>() -> T {
guard let view = self.instantiateWithOwner(nil, options: nil)[0] as? T else {
fatalError("Counldn't instantiate view from \(self)")
}
return view
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment