交互式爱情
我有一篇博文,详细介绍了这一点,但只要您的枚举的原始类型是整数,您就可以这样添加计数:enum Reindeer: Int { case Dasher, Dancer, Prancer, Vixen, Comet, Cupid, Donner, Blitzen case Rudolph static let count: Int = { var max: Int = 0 while let _ = Reindeer(rawValue: max) { max += 1 } return max }()}