[내일배움캠프]ios_swift 2일차

이시영·2023년 7월 18일

swift 기초문법

여러 가지 구문들 중 삼항 조건 연산자(Ternary Conditional Operator)를 공부했다.

삼항 조건 연산자는 question ? answer1 : answer2의 구조를 가지고 있다. question 조건이 참일경우 answer1이, 거짓인 경우 answer2가 실행된다.

예시1

a + 10 == 15 ? print(a, "is true") : print(a, "is false")

또한 삼항 조건 연산자는 if와 else를 이용해서도 구현할 수 있다.

예시2

let contentHeight = 40
let hasHeader = true
let rowHeight: Int
if hasHeader {
    rowHeight = contentHeight + 50
} else {
    rowHeight = contentHeight + 20
}
// rowHeight는 90입니다.코드를 입력하세요

꾸준한 연습이 정말 중요한 것 같다.
한순간도 성장이 멈추지 않도록 노력해야겠다.
https://school.programmers.co.kr/

0개의 댓글