-
swift 20
Nested Types 只是为了方便类型的整合和使用
struct BlackjackCard {
// nested Suit enumeration
enum Suit: Character {
case spades = "♠", hearts = "♡", diamonds = "♢", clubs = "♣"
}
// nested Rank enumeration
enum Rank: Int {
case two = 2, three, four, five, six, seven, eight, nine, ten
case jack, queen, king, ace
struct Values {
let first: Int, second: Int?
}
var values: Values {
switch self {
case .ace:
return Values(first: 1, second: 11)
case .jack, .queen, .king:
return Values(first: 10, second: nil)
default:
return Values(first: self.rawValue, second: nil)
}
}
}
// BlackjackCard properties and methods
let rank: Rank, suit: Suit
var description: String {
var output = "suit is (suit.rawValue),"
output += " value is (rank.values.first)"
if let second = rank.values.second {
output += " or (second)"
}
return output
}
}
let theAceOfSpades = BlackjackCard(rank: .ace, suit: .spades)
print("theAceOfSpades: (theAceOfSpades.description)")
// Prints "theAceOfSpades: suit is ♠, value is 1 or 11"
-
相关阅读:
查询表结构
centos使用docker发布.netcore3.0项目
<五>输入输出模型的建立及登陆验证
<二>引入NFine样式文件和登录界面
<一>前言
使用GUI工具高效构建你自己的Nuget包
Angular开发者手册重点翻译之指令(一)
WCF中操作的分界于调用顺序和会话的释放
WCF中数据契约之已知类型的几种公开方式
Singal Page App:使用Knockout和RequireJS创建高度模块化的单页应用引擎
-
原文地址:https://www.cnblogs.com/feng9exe/p/8744221.html
Copyright © 2020-2023
润新知