ios - 自动生成自定义初始化方法

标签 ios xcode init

是否可以从 Xcode 自动生成自定义 init 方法,就像 Android Studio 为 android 所做的那样? 我的意思是,如果我在 .h 中声明一些属性,例如: 诠释; 诠释 b;

所以,我想自动创建一个 init 方法:

- (id)initWithA:(int) aInner andB:(int) bInner
{
     a = aInner;
     b = bInner;
}

最佳答案

新的 Xcode(在 Xcode 10 之后)支持类的这个问题(不是结构的)。

步骤:

  1. 右击类名
  2. 点击“重构”
  3. 点击“生成成员初始化器”

enter image description here

至于结构。您可以先将其设为类,然后在获得自动生成初始化后将其更改回结构。

关于ios - 自动生成自定义初始化方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23361160/

相关文章:

ios - 如何为 64 位编译器链接 32 位框架(架构)

class - 在声明中或使用 init 初始化 Swift 类变量?

java - 在 Ubuntu 终端中运行可执行 jar 时获取错误文件。<init>

ios - 删除插入分组 UITableView 上方的空间

ios - Firebase 存储图像未在 Tableview 中下载

ios - xcodebuild 链接器断言失败

ios - 当 XCode 运行我的应用程序时执行脚本

ios - Xcode 错误 "Profile doesn' t include the beta-reports-active entitlement"for adhoc profile

xcode - 调试初始化程序时出现问题?

c# - UITextField TextColor 属性绑定(bind)问题(MVVMCross)