"Make both firstName and lastName private as well.
I don’t understand your comment about “Make both firstName and lastName private as well”.
You mark both of the Student class firstName and lastName properties with the private access control modifier and modify the student’s name in the updateName(firstName: lastName:) method like this:
class Student {
private var firstName: String
private var lastName: String
init(firstName: String, lastName: String) {
self.firstName = firstName
self.lastName = lastName
}
func updateName(firstName: String, lastName: String) -> (firstName: String, lastName: String) {
self.firstName = firstName
self.lastName = lastName
return (firstName: self.firstName, lastName: self.lastName)
}
}
let student = Student(firstName: "Ray", lastName: "Wenderlich")
let fullName = student.updateName(firstName: "Ray", lastName: "Fix")
print(fullName.firstName) // "Ray"
print(fullName.lastName) // "Fix"
Please let me know if you have any other questions or issues about the whole thing.