๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
iOS ๐ŸŽ/Swift

Swift) ์—ฐ์‚ฐ์ž == ์™€ === ์˜ ์ฐจ์ด

by yongmin.Lee 2022. 9. 24.

 

== ์—ฐ์‚ฐ์ž

a == b: a์˜ ๊ฐ’๊ณผ b์˜ ๊ฐ’์ด ๊ฐ™์€์ง€ ๊ฐ’์„ ๋น„๊ต

let value1 = 1
let value2 = 2
print(value1 == value2) // false

 

=== ์—ฐ์‚ฐ์ž

a === b: a๊ฐ€ ์ฐธ์กฐํ•˜๊ณ  ์žˆ๋Š” ์ธ์Šคํ„ด์Šค์™€ b๊ฐ€ ์ฐธ์กฐํ•˜๊ณ  ์žˆ๋Š” ์ธ์Šคํ„ด์Šค๊ฐ€ ๊ฐ™์€์ง€ ๋ ˆํผ๋Ÿฐ์Šค๋ฅผ ๋น„๊ต

let p1 = Person(id: 1, name: "kim")
let p2 = Person(id: 1, name: "kim")
let p3 = p1

print(p1 === p2) // false
print(p1 === p3) // true

 

 

`==`๋Š” stack ์˜์—ญ์˜ ๊ฐ’์„ ๋น„๊ต, `===`๋Š” heap ์˜์—ญ์˜ ๊ฐ’์„ ๋น„๊ต 

 

 

 

 

 

 

 

 

์ฐธ๊ณ ์ž๋ฃŒ

https://developer.apple.com/documentation/swift/===(_:_:)

 

'iOS ๐ŸŽ > Swift' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

Property Wrapper  (0) 2022.04.28
self vs Self  (0) 2022.04.27
RxSwift Operator : Map, FlatMap  (0) 2022.04.18
typealias, associatedtype  (0) 2022.04.15
Non-Escaping Closure ์™€ Escaping Closure  (0) 2021.12.28