- 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")
推薦閱讀
- Learn ECMAScript(Second Edition)
- Visual FoxPro程序設計教程(第3版)
- MATLAB實用教程
- CouchDB and PHP Web Development Beginner’s Guide
- Java 11 Cookbook
- 劍指大數據:企業級數據倉庫項目實戰(在線教育版)
- AIRIOT物聯網平臺開發框架應用與實戰
- Learning Node.js for .NET Developers
- Maker基地嘉年華:玩轉樂動魔盒學Scratch
- SQL Server 2016 從入門到實戰(視頻教學版)
- 一步一步跟我學Scratch3.0案例
- SSH框架企業級應用實戰
- Scratch編程從入門到精通
- Python高性能編程(第2版)
- HTML5 Game Development by Example:Beginner's Guide(Second Edition)