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

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")
主站蜘蛛池模板: 彭山县| 广德县| 邵阳县| 衡阳市| 开鲁县| 景德镇市| 西贡区| 都兰县| 宁波市| 宁都县| 昌邑市| 正宁县| 休宁县| 磐安县| 桃源县| 淮滨县| 十堰市| 广丰县| 宣城市| 琼海市| 铁岭市| 土默特左旗| 九龙县| 竹山县| 青冈县| 综艺| 迁西县| 桃江县| 黑龙江省| 汉中市| 章丘市| 同德县| 惠水县| 新巴尔虎左旗| 西华县| 光泽县| 江北区| 高碑店市| 乐昌市| 沿河| 布拖县|