Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Foundation
- struct Student {
- var firstName: String {
- willSet {
- print("We will set to \(firstName) new name \(newValue)")
- }
- didSet {
- print("New name \(firstName) has been setted instead of \(oldValue)")
- firstName = firstName.capitalized
- }
- }
- var surname: String {
- didSet {
- print("New surname \(surname) has been setted instead of \(oldValue)")
- surname = surname.capitalized
- }
- }
- var fullName: String {
- get {
- return firstName + " " + surname
- }
- set {
- let words = newValue.components(separatedBy: " ")
- if words.count > 0 {
- firstName = words[0]
- }
- if words.count > 1 {
- surname = words[1]
- }
- }
- }
- }
- var st = Student(firstName: "John", surname: "Webb")
- st.fullName = "maX kaRAtai "
- print(st)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement