slysysl slysysl - 2 months ago 10x
Swift Question

Missing Argument Label 'coder:' in Call

While trying to set up the

variable in
, a persistent compiler error is returned.

window = UIWindow(frame: UIScreen.mainScreen().bounds)

Here's the code.

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
window = UIWindow(frame: UIScreen.mainScreen().bounds)
let containerViewController = ContainerViewController()
window!.rootViewController = containerViewController

Error message is stated in the title.


You are saying:

  let containerViewController = ContainerViewController()

So you are calling the initializer with no parameters, i.e. init(). But that is not how you normally instantiate a view controller. A view controller class might have an initializer with no parameters, but because of changes you've made to your ContainerViewController, it doesn't have that initializer.

The designated initializer for a view controller is init(nibName:bundle:). So you might want to say something like this:

  let containerViewController = ContainerViewController(nibName:nil, bundle:nil)

Or, if you want to specify the nib name, go ahead and specify it instead of nil. But at least, if you put what I'm suggesting, your code should compile and then you can proceed further as you like.

Or, if you have defined some other initializer for ContainerViewController, call that initializer. (You have not shown how ContainerViewController is defined, so it's impossible to say; you have to look and see, since you have the code and we don't.) But you cannot call the initializer with no parameters, because it doesn't exist.