본문 바로가기

iOS/Swift

Swift Day_06

열거형

import SwiftUI

 

struct Choice: View {

    

    var direction: Direction = .north

    var direction2: Direction2 = .south

    var people: People = .name("sangwon")

    

    var body: some View {

        Text("방향은 \(direction.rawValue) 입니다.")

        Text("방향은 \(direction2.rawValue) 입니다.")

    }

}

 

enum Direction: String {

    case north = "북"

    case west = "서"

    case east = "동"

    case south = "남"

}

 

enum People{

    case name(String)

}

 

enum Direction2: String {

    case north = "북", west = "서", east = "동", south = "남"

}

 

#Preview {

    Choice()

}

 

'iOS > Swift' 카테고리의 다른 글

Swift Day_08  (0) 2024.07.05
Swift Day_07  (2) 2024.07.05
Swift Day_05  (0) 2024.07.04
Swift Day_04  (0) 2024.07.04
Swift Day_03  (0) 2024.07.04