missing argument for parameter in call - Swift

Hi, I am new in programming in Swift. I did this exercice:

class Client {

var name: String

var surname: String

init(name: String, surname: String) {

self.name = name

self.surname = surname

}

}

class Room {

var type: String

var client: Client

init(type: String, client: Client) {

self.type = type

self.client = client

}

}


var oneRoom = Room(type: "single")

Why give me the error: Missin argument for parameter "client" in call?

Thanks so much!

Because you clearly haven't supplied an argument for parameter client in the call!


The initializer for Room has two parameters (type and client) and neither parameter has a specified default argument, so you must pass an argument of the correct type to each parameter. Same story for Client.


let theClient = Client(name: "Thelonius", surname: "Monk")
let oneRoom = Room(type: "single", client: theClient)

If you want to be able to initialize just with the room, create another initializer :


class Room {

var type: String

var client: Client

init(type: String, client: Client) {

self.type = type

self.client = client

}

let unknown = Client() // Need to define it more precisely

convenience init(type: String) {

self.type = type

self.client = unknown

}

}

missing argument for parameter in call - Swift
 
 
Q