Created
October 18, 2017 09:30
-
-
Save 4np/6f2f967af456917a73711edc6734999b to your computer and use it in GitHub Desktop.
Swift generics Nib loading
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
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