- 작업 환경

 

https://growingsaja.tistory.com/771

 

 

 

 

 

1. playground에서 if, swith 사용해보기

 


let student: String = "철수"
            if student == "민지" {
                print("Hello, my world!")
            } else if student == "철수" {
                print("you're 철수! \(student) Welcome!")
            } else {
                print("She is 김민지")
            }
            
            let teacher: String = "이원장님"
            switch teacher {
            case "김민지":
                print("선생님이 아니야")
            case "이원장":
                print("오 \(teacher) 왔구나")
            default:
                print("기본값이다 옛다")
            }
            
            let alpha: String = "g"
            switch alpha {
            case "A"..."Z":
                print("대문자")
            case "a"..."z":
                print("소문자")
            default:
                print("뭘까용")
            }

 

 

 

 

 

2. if와 switch 사용 예시 - in 모바일로 출력하기

 

import SwiftUI

struct ContentView: View {
    var body: some View {
        VStack {
            Image(systemName: "globe")
                .imageScale(.large)
                .foregroundColor(.accentColor)
            
            let student: String = "철수"
            if student == "민지" {
                Text("Hello, my world!")
            } else if student == "철수" {
                Text("you're 철수! \(student) Welcome!")
            } else {
                Text("She is 김민지")
            }
            
            let teacher: String = "이원장님"
            switch teacher {
            case "김민지":
                Text("선생님이 아니야")
            case "이원장":
                Text("오 \(teacher) 왔구나")
            default:
                Text("기본값이다 옛다")
            }
            
            let alpha: String = "g"
            switch alpha {
            case "A"..."Z":
                Text("대문자")
            case "a"..."z":
                Text("소문자")
            default:
                Text("뭘까용")
            }
            
        }
    }
}

 

 

 

 

 

+ Recent posts