LoginSignup
2
4

More than 1 year has passed since last update.

クラスのInitを自動的に作成する

Posted at

プログラミングをしていて以下のようなモデルクラスを作成した時、Initをいちいち書くのは大変です。
Xcodeが11.4以降の自動で生成することができます。

class Product {
    var id          :String
    var name        :String
    var arriveDay   :Date
}

手順としては
1:クラス名にカーソルを合わせる
Screen Shot 2021-06-03 at 12.52.09 AM.png

2:右クリックでRefactorからGenerate Memberwise Initializerを選択することで自動生成されます。
Screen Shot 2021-06-03 at 12.57.33 AM.png

・ちなみにクラスだけではなく、構造体でも同じことができます。

2
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
4