Focus On Develop ๐ŸคŸ๐ŸคŸ

[RxSwift] RxSwift ์žฅ๋‹จ์  ๋ณธ๋ฌธ

iOS [Swift]/๊ธฐ์ดˆ๋ฅผ ํƒ„ํƒ„ํžˆ!

[RxSwift] RxSwift ์žฅ๋‹จ์ 

๋ˆ„๋ฆฌ๋‹ฌ์ดํ‹€ 2021. 3. 30. 23:16

์ง€๋‚œ ํฌ์ŠคํŒ…์—์„œ RxSwift์— ์ž…๋ฌธํ•ด๋ดค๋Š”๋ฐ์š”~!!

๊ทธ๋Ÿผ ์ด RxSwift๋Š” ์™œ์จ์•ผํ• ๊นŒ์š”~? ์žฅ๋‹จ์ ์„ ํ•œ๋ฒˆ ํŒŒํ—ค์ณ๋ณผ๊ฒŒ์š”!!


RxSwift์˜ ์žฅ์ 

1. ๋ฐ˜์‘ํ˜• ํŒจ๋Ÿฌ๋‹ค์ž„์ด ์ œ๊ณตํ•˜๋Š” ๋ช…ํ™•ํ•จ, ๋น„๋™๊ธฐ๋ฅผ ๋™๊ธฐํ™” ์ฝ”๋“œ์ฒ˜๋Ÿผ ์ž‘์„ฑ์ด ๊ฐ€๋Šฅ

2. ์ผ๊ด€์„ฑ์ด ์—†๋Š” ๋น„๋™๊ธฐ ์ฝ”๋“œ๋ฅผ ํ•˜๋‚˜์˜ ๋น„๋™๊ธฐ ์ฝ”๋“œ๋กœ ๊ฐœ๋ฐœ์ด ๊ฐ€๋Šฅ

  - ์–ด๋””์„œ๋Š” DispatchQueue, ์–ด๋””์„œ๋Š” OperationQueue.....

3. Rx๋กœ ์ผ๊ด€๋œ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•˜๋ฉด์„œ ํ™•์žฅ์ด ๋ถˆ๊ฐ€๋Šฅํ•œ ์•„ํ‚คํ…์ฒ˜ ํŒจ๋˜์„ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ์Œ

  - ์„œ๋กœ ๋‹ค๋ฅด๊ฒŒ ๊ตฌํ˜„ํ•œ ๋กœ์ง์„ ์กฐํ•ฉํ•˜๊ธฐ ์‰ฝ๊ณ , ํ™•์žฅ์ด ์–ด๋ ค์šด ๋ถ€๋ถ„์„ ํ•ด๊ฒฐ ๊ฐ€๋Šฅ

4. Thread ์ฒ˜๋ฆฌ๊ฐ€ ์‰ฌ์›Œ์ง

  - Callback ์ง€์˜ฅ์—์„œ์˜ ํƒˆ์ถœ

  - UI ์ด๋ฒคํŠธ, ๋„คํŠธ์›Œํฌ ์ฒ˜๋ฆฌ ๋“ฑ๋“ฑ ๋ฐ์ดํ„ฐ ๊ฐฑ์‹ ํ–ˆ์„ ๋•Œ์˜ ์ฒ˜๋ฆฌ๊ฐ€ ์‰ฌ์›€

5. ์ฝ”๋“œ๊ฐ€ ๊น”๋”ํ•ด์ง

6. ๋‹ค์–‘ํ•˜๊ณ  ํŽธ๋ฆฌํ•œ Operator๋“ค์ด ์ œ๊ณต๋จ

7. ํŠธ๋ Œ๋””ํ•œ ์ฝ”๋“œ๋ฅผ ์ง ๋‹ค๋Š” ๊ฐœ๋ฐœ์ž๋กœ์จ์˜ ๊ธ์ง€(?)

 

 

RxSwift์˜ ๋‹จ์ 

1. ๋Ÿฌ๋‹์ปค๋ธŒ. Swift๋ณด๋‹ค ์ƒ๋Œ€์ ์œผ๋กœ ํ•™์Šตํ•˜๊ธฐ ์–ด๋ ค์›€

2. ๋””๋ฒ„๊น…์ด ์–ด๋ ค์›€, ๊ทธ๋ž˜๋„ debug Operator๋ฅผ ํ†ตํ•ด์„œ ์–ผ์ถ” ๊ฐ€๋Šฅ!

3. ํด๋กœ์ €์˜ ์บก์ณ๋ฆฌ์ŠคํŠธ(Closure Capture List)๋ฅผ ์‹ ๊ฒฝ์จ์•ผํ•จ

  - ํด๋กœ์ € ์‚ฌ์šฉ์ด ๋งŽ์Œ

  - ์บก์ณ๋ฆฌ์ŠคํŠธ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ฉ”๋ชจ๋ฆฌ ๋ˆ„์ˆ˜๋ฅผ ์ผ์œผํ‚ค๋Š” ๋ถ€๋ถ„, ์ˆœํ™˜์ฐธ์กฐ๋ฅผ ํ”ผํ•  ์ˆ˜ ์žˆ๊ฒŒ ์‹ ๊ฒฝ์จ์•ผํ•จ

  - ์บก์ณ๋ฆฌ์ŠคํŠธ๋ฅผ ํ•ด์ฃผ์ง€ ์•Š์œผ๋ฉด race condition ๊ฐ™์€ ๊ฒƒ์ด ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ์Œ

 

 

 

Comments