Please conduct the following tasks alone. For implementation details you can refer to the lecture slides or the Apple developer website. Please do not hesitate to ask me or the tutor if you have any questions. Under "Tip" you can find some hints for the task. The "Checklist" specifies what should happen when your implementation is correct.
Open a new Playground and create a class called Person with the following three Properties:
The fullName property has a getter and a setter. In the getter, return a String that combines the firstName and the lastName Property like this:
„firstName lastName“.
In the setter, the input value is a String that should contain a first name, a space character and a last name, such as: „firstname lastname“. You should now parse the String and set the firstName Property and the lastName Property correspondingly. When using the class the results should be like in the example code below:
let person = Person(firstname: "Otto", lastname: "Hahn")
print("Firstname: \(person.firstname) Lastname: \(person.lastname)")
print("Fullname: \(person.fullname)")
person.fullname = "Hans Meiser"
print("Firstname: \(person.firstname) Lastname: \(person.lastname)")
print("Fullname: \(person.fullname)")
To find the space between the first- and last name you can use components(separatedBy: " ") method of the String class.
Extend your previously created Person class and add a custom initializer method that sets the first name and last name Properties right on object creation.
Currently the person is unfriendly because it is not able to say hello. Create a FriendlyPerson protocol that specifies a few methods that make a friendly person. Let the person class implement the protocol and call some of the friendly methods.
As the last step, create a Person instance and test the implementation
You can define the FriendlyPerson protocol in the Playground just before the Person class.