Smart Device/Swift
Swift extension #6 Nested Types
언덕너머에
2015. 6. 25. 22:38
Nested Types
예
extension Int {enum Kind {case Negative, Zero, Positive}var kind: Kind {switch self {case 0:return .Zerocase let x where x > 0:return .Positivedefault:return .Negative}}}
func printIntegerKinds(numbers: [Int]) {for number in numbers {switch number.kind {case .Negative:print("- ", appendNewline: false)case .Zero:print("0 ", appendNewline: false)case .Positive:print("+ ", appendNewline: false)}}print("")}printIntegerKinds([3, 19, -27, 0, -6, 0, 7])// prints "+ + - 0 - 0 +"