Develope/Swift
Swift 기초 - 비교 연산자 ( isEqualToString ? )
Jason park@
2016. 6. 12. 00:00
반응형
* Swift 비교 연산자
수의 기본적인 비교 연산은 타 언어와 다를게 없으므로 패스
문자열 비교 연산은 objective-c 의 [변수명 isEqualToString:@"비교문자열"] 처럼 쓸줄 알았는데
너무 심플해졌다.
let name = "world"
if name == "world" {
print("hello, world")
} else {
print("I'm sorry \(name), but I don't recognize you")
}
그냥 비교 연산자만 쓰면 된다.
또한 동시에 여러 변수를 if or 처럼 사용도 할수 있다.
(1, "zebra", 3) < (2, "apple", 2) // true because 1 is less than 2
(3, "apple") < (3, "bird") // true because 3 is equal to 3, and "apple" is less than "bird"
(3, "car") < (3, "bird") // false because "bird" is less than "car"
(4, "dog") == (4, "dog") // true because 4 is equal to 4, and "dog" is equal to "dog”
끝.
반응형