-{UITableViewController initWithStyle:] should NOT call [self initWithNibName:bundle:]

Originator:jgallagher
Number:rdar://17879122 Date Originated:July 31, 2014
Status:Open Resolved:
Product:iOS SDK Product Version:7, 8
Classification:Serious Bug Reproducible:Always
 
Summary:
Due to Swift’s more rigid rules about designated and convenience initializers, the implementation of -[UITableViewController initWithStyle:] is problematic. If I have a subclass of UITableViewController, and I want to define a new designated initializer:

class MyTableVC : UITableViewController {
	let foo: Int
	init(foo: Int) {
		self.foo = foo
		super.init(style: .Grouped)
	}
}

This will build but crash at runtime because MyTableVC doesn’t implement init(nibName:bundle:). However, it shouldn’t have to! If we implement that method, we have a problem with the “foo” property:

class MyTableVC : UITableViewController {
	let foo: Int
	init(foo: Int) {
		self.foo = foo
		super.init(style: .Grouped)
	}
	init(nibName: String!, bundle: String!) {
		// what do we set foo to?
		super.init(nibName: nibName, bundle: bundle)
	}
}

If backwards compatibility is a problem, perhaps a new (truly designated) initializer could be added to UITableViewController for use from Swift subclasses.

Notes:

See some discussion here: https://devforums.apple.com/message/987922

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!