objective-c - 我应该在 Objective C 类中的什么位置设置默认变量值

标签 objective-c ios variables default-value

我不能在头文件中设置默认值,那么应该在哪里设置呢?在类的指定初始化程序中?

最佳答案

是的,如果您需要特定的值,请使用类似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/

相关文章:

objective-c - UIToolbar 在 iOS 7 中不是半透明的

ios - 从包含 HTML 的 NSString 创建本地 NSURL?

iphone - Objective-C 错误

ios - 如何使用 URLSeassion 显示下载进度

php变量改变结果

ios - UISlider thumbTintColor 在 iOS 7 上没有改变(在 iOS 6 上很好)

iphone - iOS Gamecenter 程序化配对

iOS:子类化 UIPickerView 未在主视图中加载

c++ - 在 C++ 中将一个字符串值赋给一个整型变量会发生什么?

variables - 变量的不同行为和函数的返回值