简体   繁体   English

检查 xcode 中的指定初始值设定项

[英]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关键字:

  • 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)在 Xcode 中类的定义中(右键单击 > 跳转到定义)

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.

相关问题 指定的初始化程序仅应在“超级” xcode 6.3.1上调用指定的初始化程序 - Designated initializer should only invoke a designated initializer on 'super' xcode 6.3.1 在Xcode 6中关闭指定的初始化程序检查 - Turn off designated initializer checking in Xcode 6 指定初始化器 - Designated Initializer iOS-预期的NS_DESIGNATED_INITIALIZER:(冒号)在xcode 5中 - iOS - NS_DESIGNATED_INITIALIZER expected : (colon) in xcode 5 Xcode 7.3.1 Swift“初始化程序未从其超类覆盖指定的初始化程序”错误 - Xcode 7.3.1 Swift “initializer does not override a designated initializer from its superclass” error UITextView 的指定初始化器 - Designated Initializer of UITextView 指定的初始化程序缺少对超类的指定初始化程序的超级调用 - designated initializer missing a super call to a designated initializer of the super class iOS指定的初始化程序:使用NS_DESIGNATED_INITIALIZER - iOS Designated Initializers : Using NS_DESIGNATED_INITIALIZER 必须调用超类'UITableViewCell'的指定初始值设定项 - Must call a designated initializer of the superclass 'UITableViewCell' 无法在NSManagedObject类“建筑物”上调用指定的初始化程序 - Failed to call designated initializer on NSManagedObject class 'building'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM