我不能在头文件中设置默认值,那么应该在哪里设置呢?在类的指定初始化程序中?
最佳答案
是的,如果您需要特定的值,请使用类似init
的方法。
这是推荐的方式。
The designated initializer is the method in each class that guarantees inherited instance variables are initialized (by sending a message to super to perform an inherited method). It’s also the method that does most of the work, and the one that other initialization methods in the same class invoke. It’s a Cocoa convention that the designated initializer is always the method that allows the most freedom to determine the character of a new instance (usually this is the one with the most parameters, but not always).
关于objective-c - 我应该在 Objective C 类中的什么位置设置默认变量值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7443799/