나의 발자취
Swift Notes for Professionals PDF (2) Booleans 요약 본문
Section 5.2: Booleans and Inline Conditionals (불리언과 삼항연산자)
Boolean 값을 가지는 인자 value를 함수 내부에서 삼항연산자로 받아서 이것을 String안에 나타내는~
func isTurtle(_ value: Bool) {
let color = value ? "green" : "red"
print("The animal is \(color)")
}
isTurtle(true) // outputs 'The animal is green'
isTurtle(false) // outputs 'The animal is red'
Section 5.3: Boolean Logical Operators
OR ( || ), AND ( && ), XOR ( ^ )
XOR 연산자는 두 operands 중에서 하나만 true값을 가져도 true 값을 반환하는 것이다.
if (10 < 20) ^ (20 < 10) {
print("Expression is true")
}
// Expression is true
Section 5.4: Negate a Bool with the prefix ! operator
!는 logical negation(논리적 부정)을 담당하는 연산자이다.
print(!true) // prints "false"
print(!false) // prints "true"
func test(_ someBoolean: Bool) {
if !someBoolean {
print("someBoolean is false")
}
}
'앱 개발 > iOS' 카테고리의 다른 글
[iOS] 로컬에 데이터를 저장하는 PList (2) | 2024.10.21 |
---|---|
Swift Notes for Professionals PDF (3) Arrays (1) | 2024.09.19 |
Swift Notes for Professionals PDF (1) 문자열 (0) | 2024.09.19 |
iOS 무한 스크롤 구현하는 법: How to implement an Infinite Scrolling List (2) | 2024.09.16 |
XCode에서 마크다운 형식 보는법 - 단축키 한번에 (0) | 2024.09.11 |
Comments