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

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")
主站蜘蛛池模板: 淳化县| 中山市| 双峰县| 黑龙江省| 汶川县| 孟州市| 洛阳市| 龙山县| 会昌县| 吉林市| 民勤县| 永登县| 新源县| 平远县| 五台县| 崇州市| 深水埗区| 东阿县| 砚山县| 颍上县| 阳朔县| 登封市| 醴陵市| 浠水县| 安溪县| 肃北| 东港市| 卓尼县| 沾益县| 庐江县| 西宁市| 晋江市| 贵定县| 平邑县| 封丘县| 绥江县| 岗巴县| 兴国县| 洪江市| 故城县| 梅州市|