[英]Check designated initializer in xcode
Is there any way to find out which initializer is the designated one in super class in Xcode?有没有办法找出Xcode中超类中指定的初始化程序?
I type super().init.. then, Xcode shows all initializers of superclass.我输入 super().init.. 然后,Xcode 显示超类的所有初始值设定项。 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.
子类中的指定构造器(DI)只能调用超类中的便利构造器(CI),因为超类中的 CI 最终会调用超类中的 DI。 Correct me if I'm wrong, thanks.
如果我错了,请纠正我,谢谢。
In Swift, any initializer not marked with the keyword "convenience" is a designated initializer. 在Swift中,任何未标记关键字“ convenience”的初始化程序都是指定的初始化程序。
And designated initializers are required to call a designated initializer in their immediate superclass, per The Swift Programming Language . 根据The Swift Programming Language的要求,指定的构造方法必须在其直接超类中调用指定的构造方法 。 They cannot call a convenience initializer.
他们不能调用便捷初始化程序。
For anyone new to Xcode - this confused me for a while too.对于 Xcode 的新手来说——这也让我困惑了一段时间。 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 .缺少
convenience
关键字定义了指定的初始值设定项,但是根据您查看的位置,您不会总是看到 'convenience' 关键字。
You can see the convenience
keyword:您可以看到
convenience
关键字:
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) (使用 Xcode 13.1)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.