Nested Types
예
extension Int {
enum Kind {
case Negative, Zero, Positive
}
var kind: Kind {
switch self {
case 0:
return .Zero
case let x where x > 0:
return .Positive
default:
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 +"
'Smart Device > Swift' 카테고리의 다른 글
Swift extension #5 subscript 확장 (0) | 2015.06.25 |
---|---|
Swift extension #4 Mutating Instance Methods (0) | 2015.06.25 |
Swift extension #3 Method의 확장 (0) | 2015.06.25 |
Swift extension #2 Initializers의 확장 (0) | 2015.06.25 |
Swift extension #1 기존 자료형의 확장 (0) | 2015.06.25 |