简体   繁体   中英

Extra argument in call - swift

I have made a simple class just for practice but I have a problem with a extra argument call, I have understand this often is a case of declaring wrongly but I can't understand why this isn't working.

What do I do wrong?

   class Room {
       var number : Int?
       var status : Int?
   }

   var roomArray = [Room]()

   for i in 0...9 {
       let newRoom = Room(number: (100+i) , status: 0) // here is the error
       roomArray.append(newRoom)
   }

You need this init in your class to set the values.

class Room {
    var number : Int?
    var status : Int?

    init(number number: Int, status: Int) {
        self.number = number
        self.status = status
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM