I'm looking for an explanation of why the following prints false
when run on iOS. The view controller is instantiated from a dead-simple Storyboard which just contains a single table view.
I'm using the preloading trick suggested by https://stackoverflow.com/a/33658528/1919412 to allow Interface Builder to find the MyTableViewController
class. I'm sure that has something to do with the problem, but I'd like to better understand what's going on.
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
// If we don't create this dummy instance before our real view controller gets loaded from storyboard, we get this error:
// "Unknown class _TtC21ViewControllerInitBug21MyTableViewController in Interface Builder file."
// See: https://stackoverflow.com/a/33658528/1919412
let foo = MyTableViewController()
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
return true
}
}
class Foo<T>:UITableViewController {
init() {
super.init(style:.Plain)
}
}
class MyTableViewController:Foo<String> {
private var foo = true
override func viewDidLoad() {
super.viewDidLoad()
print(self.foo)
}
}