Skip to content

Instantly share code, notes, and snippets.

@4np
Created October 18, 2017 09:30
Show Gist options
  • Save 4np/6f2f967af456917a73711edc6734999b to your computer and use it in GitHub Desktop.
Save 4np/6f2f967af456917a73711edc6734999b to your computer and use it in GitHub Desktop.
Swift generics Nib loading
import Foundation
extension UIView {
class func fromNib<T : UIView>() -> T {
//swiftlint:disable:next force_unwrapping
return Bundle.main.loadNibNamed(String(describing: T.self), owner: nil, options: nil)![0] as! T
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment