Avatar
omochimetaru 4/5/2021 7:49 AM
func calculatePaymentPrice(_ price : Int) -> Int { if price < 0 { 0 } else { Int(Double(price) * 1.1) } } こうなるって話をしてると思ってます。式1つなのでreturnは省略しました。
7:51 AM
ちなみに現状のSwiftでも func calculatePaymentPrice2(_ price : Int) -> Int { price < 0 ? 0 : Int(Double(price) * 1.1) } func calculatePaymentPrice3(_ price : Int) -> Int { ifx (price < 0) { 0 } else: { Int(Double(price) * 1.1) } } ↑この2つの書き方はできます。(ifxは自作の関数)