1

Is there any way to find out which initializer is the designated one in super class in Xcode?
I type super().init.. then, Xcode shows all initializers of superclass. I want to know is there any sign or symbol to point out which is the designated one?

Also a quick question. A designated initializer(DI) in subclass is allowed to only call a convenience initializer(CI) in superclass since the CI in superclass will eventually call the DI in superclass. Correct me if I'm wrong, thanks.

Yao
  • 709
  • 2
  • 11
  • 22
  • I am lacking this option often. Don't understand why it's not provided, when typing super.init you essentially get a bunch of invalid completions, which makes little sense. – Philip De Vries Sep 02 '21 at 18:14

2 Answers2

2

In Swift, any initializer not marked with the keyword "convenience" is a designated initializer.

And designated initializers are required to call a designated initializer in their immediate superclass, per The Swift Programming Language. They cannot call a convenience initializer.

Marc Khadpe
  • 2,012
  • 16
  • 14
1

For anyone new to Xcode - this confused me for a while too. The absence of the convenience keyword is what defines a designated initializer, but depending on where you look, you won't always see the 'convenience' keyword.

You can see the convenience keyword:

  • on the 'Developer documentation' page for the individual initializer
  • in the 'Quick help' (right click > Show quick help, or the 'Quick help' pane on the right)
  • in the definition of the class in Xcode (right click > Jump to definition)

You can't see it when looking at the overview of the class in the 'Developer documentation', or in code suggestions as you type.

(Using Xcode 13.1)

Brendan Lane
  • 117
  • 2
  • 8