arithmetic operator (산술연산자)
- 숫자 타입에 대해 +, -, *, / 연산 가능
- 정수형 숫자 타입에 대해서는 나머지 % 연산도 가능
operator overloading
- 연산자는 타입에 따라 연산을 가질 수 있음
+ 의 경우, String, array 등 각 타입에 따라 연산됨
let str1="aaa"
let str2="bbb"
let str = str1+str2 // "aaabbb"
let names1 = ["April", "Bob"]
let names2 = ["Chuck", "David"]
let names = names1+names2 // ["April", "Bob", "Chuck", "David"]
switch statement
if-else 외에도 switch 를 이용해서 conditions을 확인할 수 있음
(다만, 조건의 모든 케이스가 커버가 되게끔 작성해야함)
- 이전에 배웠던
enum 타입과 같이 쓰기 좋음
enum Direction {
case up
case down
case left
case right
}
let direcition = Direction.down
switch direcition {
case .up:
print("up")
case .down:
print("down")
case .left:
print("left")
case .right:
print("right")
}