Skip to content

Instantly share code, notes, and snippets.

@susieyy
Created January 14, 2017 02:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save susieyy/74de0a4e652952f55fa4e8fe7cef5034 to your computer and use it in GitHub Desktop.
Save susieyy/74de0a4e652952f55fa4e8fe7cef5034 to your computer and use it in GitHub Desktop.
#swtws
protocol InstantiatableFromNib {
static var nibName: String { get }
static func instantiateFromNib() -> Self
}
extension InstantiatableFromNib where Self: UIView {
static var nibName: String {
get { return String(Self.self) }
}
static func instantiateFromNib() -> Self {
let nib = UINib(nibName: nibName, bundle: nil)
return nib.instantiateWithOwner(nil, options: nil).first as! Self
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment