Is there difference between using a constructor and using .init?

后端 未结 2 389
长情又很酷
长情又很酷 2021-01-22 11:16

Let\'s say I have a class:

class Fruit {
    var fruitName: String

    init(getFruit name: String) {
        fruitName = name
    }

}

Is ther

2条回答
  •  独厮守ぢ
    2021-01-22 12:01

    To my knowledge, there is absolutely no difference.

    It is generally convention in Swift to call the constructor without the .init This is the 'swiftier' shorthand.

提交回复
热议问题