Swift subclassing - how to override Init()

前端 未结 4 595
面向向阳花
面向向阳花 2021-02-01 13:40

I have the following class, with an init method:

class user {
  var name:String
  var address:String

  init(nm: String, ad: String) {
    name = nm
    address          


        
4条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-01 14:00

    You pass arguments to an initializer much like you pass arguments to a normal method:

    init(nm: String, ad: String) {  
        super.init(nm: nm, ad: ad) 
    }
    

    For reference, this is shown in the Designated and Convenience Initializers In Action section of the Swift Language Guide.

提交回复
热议问题