LoginSignup
1
1

More than 5 years have passed since last update.

enumを使って結果をハンドリングする Swift 3.0

Last updated at Posted at 2017-07-04

例えば、以下の例は、オーブンの電源がついているか、消えているか判定している。
オーブンが付いていた場合は、温度付きのStringを返す。


import UIKit

enum OvenState{
    case on(Double)
    case off
}

var ovenState = OvenState.on(450)

switch ovenState{
case let .on(temperature):
    print("The oven is on and set to \(temperature) degrees")
case .off:
    print("The oven is off")
}
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1