您可以这样做,这可能会有所帮助:(这只是一个非常通用的示例)
enum Country : Int {
case Moldova, Botwana;
//
func capital() -> String {
switch (self) {
case .Moldova:
return "Chișinău"
case .Botwana:
return "Gaborone"
default:
return ""
}
}
//
func flagColours() -> Array<UIColor> {
switch (self) {
case .Moldova:
return [UIColor.blueColor(), UIColor.yellowColor(), UIColor.redColor()]
case .Botwana:
return [UIColor.blueColor(), UIColor.whiteColor(), UIColor.blackColor()]
default:
return []
}
}
//
func all() -> (capital: String, flagColours: Array<UIColor>) {
return (capital(), flagColours())
}
//
var capitolName: String {
get {
return capital()
}
}
//
var flagColoursArray: Array<UIColor> {
get {
return flagColours()
}
}
}
那么您可以像这样访问详细信息:
let country: Country = Country.Botwana
获取资本
那样:
let capital: String = country.capital()
或其他:
let capital: String = country.all().capital
或第三个:
let capital: String = country.capitolName
获取标志的颜色:
那样:
let flagColours: Array<UIColor> = country.flagColours()
或其他:
let flagColours: Array<UIColor> = country.all().flagColours
或第三个:
let flagColours: Array<UIColor> = country.flagColoursArray