SweepSwift iOS ๋ฉด์ ์ง๋ฌธ์ ๋ํ ๋ต์ ์์ฑํ ๊น์ iOS ๊ฐ๋ฐ์๋ผ๋ฉด ์ฑ์ ๊ธฐ๋ฅํฅ์ ๋ฉด์์ ๊ผญ ๊ณ ๋ คํด๋ด์ผํ๋ค๋ Method Dispatch์ ๋ํด ์ ๋ฆฌํด๋ณด๊ธฐ๋ก ํ๋ค.
โ๏ธ Method Dispatch
Method dispatching is the process of finding the address of instructions to be executed by the CPU when a particular method is called.
์ด๋ค ์ธ์คํด์ค์ ํธ์ถ๊ตฌ๋ฌธ์์ ํ๋ก๊ทธ๋จ์ด ์ด๋ค ๋ฉ์๋๋ฅผ ์คํํ ์ง ์ ํํ๋ ๊ฒ์ ๋ฉ์๋ ๋์คํจ์น๋ผ๊ณ ํ๋ค.
์ด๋ ์์ (์ปดํ์ผํ์ vs ๋ฐํ์)์ ์ด๋ค method๋ฅผ ์ฌ์ฉํ ์ง๋ฅผ ๊ฒฐ์ ํ๋๋์ ๋ฐ๋ผ์ Static Dispatch์ Dynamic Dispatch๋ก ๋๋๋ค.
์ฌ์ค ์ข ๋ฅ๋ Inline Dispatch, Virtual Dispatch๋ฅผ ํฌํจํ์ฌ 4๊ฐ์ง์ธ๋ฐ, ์ฃผ๋ก ๊ณ ๋ คํด์ผํ๋ ๊ฑด Dynamic Dispatch์ Static Dispatch๋ค.
- ๋ฐํ์์ ๊ฒฐ์
- ์ฐธ์กฐํ์ (Class)
- ํด๋์ค์ ๊ฒฝ์ฐ ์ปดํ์ผ ํ์์์ ์ฐธ์กฐ๋ ์์์ ์์น๊ฐ ๋ช ํํ๊ฒ ๊ฒฐ์ ๋์ง ์๊ธฐ ๋๋ฌธ์ ๋ฐํ์์์ ์ค์ ์ฐธ์กฐ๋ ์์๊ฐ ๊ฒฐ์ ๋๋ค. ์ด ๊ณผ์ ์ผ๋ก ์ธํด ์ค๋ฒํค๋๊ฐ ๋ฐ์ํ ์ ์๋ค.
- ์ด๋ค ์๋ธํด๋์ค๊ฐ ๋ค์ด์๋ ์ค์ ์ ๋ง๋ ์์๋ฅผ ์ฐธ์กฐํ๊ธฐ ๋๋ฌธ์ ๋คํ์ฑ ํ์ฉ์ ์ ๋ฆฌ
- final ํค์๋๋ฅผ ํตํด ์ฐธ์กฐํ์ ์ธ ๊ฒฝ์ฐ ํน์ ์ธ์คํด์ค๋ฅผ ์ฌ์์์ ๋ฐฉ์งํ์ฌ ์ ์ ๋์คํจ์น๋ก ๋ง๋ค์ด ์ฑ๋ฅ์ ํฅ์ ์ํฌ ์ ์๋ค.
- ์ปดํ์ผ ํ์์ ๊ฒฐ์
- ๊ฐํ์ ๊ณผ ์ฐธ์กฐํ์ (class, struct ๋ชจ๋)์์ ๋ชจ๋ ์ฌ์ฉ์ด ๊ฐ๋ฅํ๋ค.
- protocol๊ณผ extension์ Static Dispatch์์ ๋์ํ๋ค.
- Static Dispatch๊ฐ Dispatch ์ข ๋ฅ ์ค ์๋๊ฐ ๊ฐ์ฅ ๋น ๋ฅธ๋ฐ, ๊ทธ ์ด์ ๊ฐ static dispatch prohibits methods from being overridden, resulting in only one implementation of each method. ์ฆ, ์ฌ์์์ ๋ฐฉ์งํด์์ด๋ค.
๐ References
https://medium.com/@ilichev/method-dispatch-in-swift-da0d3993fc76
Method Dispatch in Swift
Introduction
medium.com
'๐ Dev > Swift' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Swift] Keychain vs UserDefaults (0) | 2023.12.17 |
---|---|
[Swift] unowned vs weak (2) | 2023.11.14 |