스위치
import SwiftUI
struct Selction: View {
@State var mydirection: Direction4 = .east
var body: some View {
switch mydirection {
case .north:
Text("북 춥다")
case .west:
Text("서 해가 진다.")
case .east:
Text("동 해가 뜬다.")
case .south:
Text("남 덥다")
default:
Text("그 외")
}
Button{
switch mydirection {
case .north:
mydirection = .east
case .west:
mydirection = .north
case .east:
mydirection = .south
case .south:
mydirection = .west
}
}label: {
Text("클릭")
}
}
}
enum Direction4: String {
case north = "북"
case west = "서"
case east = "동"
case south = "남"
}
#Preview {
Selction()
}
'iOS > Swift' 카테고리의 다른 글
Swift Day_09 (0) | 2024.07.06 |
---|---|
Swift Day_08 (0) | 2024.07.05 |
Swift Day_06 (0) | 2024.07.05 |
Swift Day_05 (0) | 2024.07.04 |
Swift Day_04 (0) | 2024.07.04 |