Skip to content

Instantly share code, notes, and snippets.

@morizotter
Last active October 20, 2015 16:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save morizotter/16d46f263b9b80f9331a to your computer and use it in GitHub Desktop.
Save morizotter/16d46f263b9b80f9331a to your computer and use it in GitHub Desktop.
StoryboardやXibファイルからインスタンスを生成するprotocol ref: http://qiita.com/morizotter/items/f25bf03fa4e151703451
protocol InstantiateFromNibable {
typealias Instance
static func instantiateFromNib() -> Instance
}
final class LoadingFooterView: UIView, InstantiateFromNibable {
static func instantiateFromNib() -> LoadingFooterView {
return UINib(nibName: "LoadingFooterView", bundle: nil).instantiateWithOwner(nil, options: nil).first as! LoadingFooterView
}
let footerView = LoadingFooterView.instantiateFromNib()
final class SearchViewController: UIViewController, InstantiateFromNibable {
static func instantiateFromNib() -> SearchViewController {
return UIStoryboard(name: "Search", bundle: nil).instantiateViewControllerWithIdentifier("SearchViewController") as! SearchViewController
}
let vc = SearchViewController.instantiateFromNib()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment