본문 바로가기

Swift

Swift 정리 : 함수로부터 여러개의 결과 반환하기

func converter(length: Float) -> (yards: Float, centimeters: Float, meters: Float) {
let yards = length * 0.0277778
let centimeters = length * 2.54
let meters = length * 0.0254
return (yards, centimeters, meters)
}
var lengthTuple = converter(length:100)
print(lengthTuple) //(yards: 2.77778, centimeters: 254.0, meters: 2.54)
print(lengthTuple.yards) //2.77778
print(lengthTuple.centimeters) //254.0
print(lengthTuple.meters) //2.54