官术网_书友最值得收藏!

How to do it...

We have already defined a Person object as having three separate string properties relating to the person's name; however, these three separate strings don't exist in isolation from each other--they together define a person's name. Currently, to get a person's name, you have to access three separate properties and combine them. Let's tidy this up by defining a person's name as its own struct. Enter the following code into the playground and run the playground:

struct PersonName { 
let givenName: String
let middleName: String
var familyName: String

func fullName() -> String {
return "\(givenName) \(middleName) \(familyName)"
}

mutating func change(familyName: String) {
self.familyName = familyName
}
}
var alissasName = PersonName(givenName: "Alissa", middleName: "May", familyName: "Jones")
主站蜘蛛池模板: 临泉县| 承德县| 无锡市| 清水县| 濮阳市| 邻水| 黄梅县| 永福县| 鱼台县| 富阳市| 香港 | 三亚市| 太康县| 刚察县| 潜山县| 冀州市| 富顺县| 白河县| 彭山县| 苏尼特右旗| 修水县| 永吉县| 潮州市| 鹰潭市| 鹿泉市| 亚东县| 金门县| 宿州市| 五寨县| 建瓯市| 安新县| 井陉县| 宣武区| 阳朔县| 石阡县| 同江市| 大石桥市| 泰和县| 惠安县| 苏尼特左旗| 怀宁县|