iOS ๐ŸŽ/Swift

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

yongmin.Lee 2022. 9. 24. 16:13

 

== ์—ฐ์‚ฐ์ž

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/===(_:_:)