- 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")
推薦閱讀
- Mastering Entity Framework Core 2.0
- C#程序設計教程
- HDInsight Essentials(Second Edition)
- Learning JavaScript Data Structures and Algorithms
- 速學Python:程序設計從入門到進階
- 軟件工程基礎與實訓教程
- Serverless Web Applications with React and Firebase
- Android Studio Cookbook
- OpenCV with Python Blueprints
- Python編程快速上手2
- Apache Solr for Indexing Data
- Java服務端研發知識圖譜
- JavaScript高級程序設計(第4版)
- LiveCode Mobile Development Hotshot
- Computer Vision with Python 3