- Swift 4 Programming Cookbook
- Keith Moon
- 121字
- 2021-07-08 10:21:26
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")
推薦閱讀
- Dynamics 365 for Finance and Operations Development Cookbook(Fourth Edition)
- Visual C++程序設(shè)計(jì)學(xué)習(xí)筆記
- Python入門很簡(jiǎn)單
- Instant Typeahead.js
- 零基礎(chǔ)學(xué)單片機(jī)C語(yǔ)言程序設(shè)計(jì)
- Getting Started with Greenplum for Big Data Analytics
- C#應(yīng)用程序設(shè)計(jì)教程
- ASP.NET程序開發(fā)范例寶典
- GameMaker Essentials
- OpenCV with Python By Example
- Flask Web開發(fā):基于Python的Web應(yīng)用開發(fā)實(shí)戰(zhàn)(第2版)
- 算法設(shè)計(jì)與分析:基于C++編程語(yǔ)言的描述
- Practical Predictive Analytics
- Solr權(quán)威指南(下卷)
- 關(guān)系數(shù)據(jù)庫(kù)與SQL Server 2012(第3版)