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

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")
主站蜘蛛池模板: 邻水| 马龙县| 绥宁县| 苍梧县| 延津县| 邮箱| 萍乡市| 岚皋县| 门源| 莱州市| 资中县| 景泰县| 全州县| 西城区| 陇川县| 天津市| 鹤庆县| 福鼎市| 汤阴县| 来凤县| 长乐市| 宁德市| 报价| 黔江区| 雅江县| 岗巴县| 麻栗坡县| 深圳市| 台北县| 澄江县| 盱眙县| 沐川县| 丰宁| 神农架林区| 满洲里市| 江孜县| 全椒县| 昌宁县| 宁陕县| SHOW| 无棣县|