swift 枚举の実験1
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了swift 枚举の実験1相关的知识,希望对你有一定的参考价值。
//: Playground - noun: a place where people can play
import Foundation
var str = "Hello, playground"
enum Planet_whoAreYou {
case Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus, Neptune
func next() -> Planet_whoAreYou {
switch self {
case .Mercury: return .Venus
case .Venus: return .Earth
case .Earth: return .Mars
case .Mars: return .Jupiter
case .Jupiter: return .Saturn
case .Saturn: return .Uranus
case .Uranus: return .Neptune
case .Neptune: return .Mercury
}
}
func prev() -> Planet_whoAreYou {
switch self {
case .Mercury: return .Neptune
case .Venus: return .Mercury
case .Earth: return .Venus
case .Mars: return .Earth
case .Jupiter: return .Mars
case .Saturn: return .Jupiter
case .Uranus: return .Saturn
case .Neptune: return .Uranus
}
}
}
enum Planet_Int: Int {
case Mercury = 1, Venus, Earth, Mars, Jupiter, Saturn, Uranus, Neptune
}
enum Planet_String: String {
case Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus, Neptune
}
let MAX = 1
let somebodyArray = Array<Planet_whoAreYou>(count:MAX, repeatedValue: .Earth)
let stringArray = Array<Planet_String>(count:MAX, repeatedValue: .Mercury)
let intArray = Array<Planet_Int>(count:MAX, repeatedValue: .Jupiter)
func toStringYYY(val:Planet_whoAreYou) -> String {
return String(val)
}
for x in somebodyArray {
print(x)
// -> Earth
print(x.next())
// -> Mars
switch String(x) {
case "Mercury":print(x)
default: break
}
}
for x in stringArray {
let strA = String(x)
print(strA)
// -> Mercury
print(x)
// -> Mercury
print("\(x) = \(x.rawValue)")
// -> Mercury
switch x.rawValue {
case "Mercury":print(x)
default: break
}
}
for x in intArray {
print(String(x))
// -> Jupiter
//print(Int(x)) initializerはinvokeできない
print("\(x) = \(x.rawValue)")
// -> Jupiter = 5
switch String(x) {
case "Mercury":print(x)
default: break
}
}
以上是关于swift 枚举の実験1的主要内容,如果未能解决你的问题,请参考以下文章
ruby nokogiriで実験する为のテンプレ
机器学习文本挖掘之spherical k-means algorithm初识
html GoogleMap的でルート検索のオプションを実験
swift枚举_003_swift枚举类型
text PowerShell中で卷曲の実行
markdown メール机能の実装