Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate custom init method automatically

Tags:

xcode

ios

init

Is it possible to generate custom init method automatically from Xcode, as Android Studio does for android? I mean, if I declare some properties in .h, for example: int a; int b;

So, I would like to create automatically a init method as:

- (id)initWithA:(int) aInner andB:(int) bInner
{
     a = aInner;
     b = bInner;
}
like image 435
Javier Roberto Avatar asked Apr 29 '14 09:04

Javier Roberto


1 Answers

New Xcode (after Xcode 10) support this issue for class (not for struct).

Steps:

  1. right click on class name
  2. click "refactor"
  3. click "Generate Memberwise Initializer"

enter image description here

As for struct. You can make it class first, and change it back to struct after you get auto-gen init.

like image 100
Wu Yuan Chun Avatar answered Oct 12 '22 06:10

Wu Yuan Chun