Skip to content

Instantly share code, notes, and snippets.

@jbrennan
Created October 28, 2014 21:52
Show Gist options
  • Save jbrennan/a2aeb523b68701c50c22 to your computer and use it in GitHub Desktop.
Save jbrennan/a2aeb523b68701c50c22 to your computer and use it in GitHub Desktop.
Generic UIViewController subclass
// usage
let pop = PopoverViewController<SomeViewController>()
self.showViewController(pop) // adds pop.view as a subview (stepping over this line reveals that pop.view becomes non-nil)
// -viewDidLoad is not called...
class PopoverViewController<ContentViewControllerType: UIViewController>: UIViewController {
var omitted: Whatever?
// I'm not entirely sure why I need these initializers, considering I have one optional var property...
override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
}
required init(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
convenience override init() {
self.init(nibName: nil, bundle: nil)
}
// Not called!
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = UIColor.orangeColor()
}
}
@ccwasden
Copy link

ccwasden commented Dec 5, 2014

I am doing something similar:

class SimpleListViewController<ItemType>: UITableViewController {
...
}

let listVC = SimpleListViewController<State>()
listVC.items = states
listVC.title = "SELECT STATE"
let navController = UINavigationController(rootViewController: listVC)

and I get Unrecognized selector -[Swift._IndirectArrayBuffer setTitle:] on both the title line and the navController line whichever comes first. Related you think? Did you ever figure this out?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment