๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๐ŸŽ iOS/RxSwift

(6)
[RxSwift] Traits - Driver, Signal, Control Property/ControlEvent ์•ˆ๋…•ํ•˜์„ธ์š” ์ œ์ธ์ž…๋‹ˆ๋‹ค :) ์ง€๋‚œ ๊ฒŒ์‹œ๊ธ€์— ์ด์–ด ์ด๋ฒˆ ๊ฒŒ์‹œ๊ธ€์—์„œ๋Š” RxCocoa์˜ Traits์— ๋Œ€ํ•ด ์ •๋ฆฌํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. ์ด๋ฒˆ ๊ฒŒ์‹œ๊ธ€๋„ ReactiveX/RxSwift์˜ Traits ๋ฌธ์„œ ๋ฒˆ์—ญ์„ ํ†ตํ•ด ์ž‘์„ฑํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค! RxCocoa Traits์˜ ์ข…๋ฅ˜ RxCocoa์˜ Traits๋กœ๋Š” Driver, Signal, Control Property/ControlEvent๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. ํ•˜๋‚˜์”ฉ ์‚ดํŽด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค! Driver Driver๋Š” ๊ฐ€์žฅ ์ •๊ตํ•œ trait์ž…๋‹ˆ๋‹ค. UI ๊ณ„์ธต์—์„œ reactive ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•˜๋Š” ์ง๊ด€์ ์ธ ๋ฐฉ๋ฒ•์„ ์ œ๊ณตํ•˜๊ฑฐ๋‚˜ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๊ตฌ๋™(driving)ํ•˜๋Š” ๋ฐ์ดํ„ฐ ์ŠคํŠธ๋ฆผ์„ ๋ชจ๋ธ๋งํ•˜๋ ค๋Š” ๋ชจ๋“  ๊ฒฝ์šฐ์— ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. + Driver๋ผ๋Š” ์ด๋ฆ„์ด ๋ถ™์€ ์ด์œ ? Driver์˜ ๋ชฉ์  ์ž์ฒด๊ฐ€ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๊ตฌ..
[RxSwift] Traits - Single, Completable, Maybe ์•ˆ๋…•ํ•˜์„ธ์š” ์ œ์ธ์ž…๋‹ˆ๋‹ค! ์˜ค๋Š˜์€ Traits๊ฐ€ ๋ฌด์—‡์ธ์ง€์— ๋Œ€ํ•ด ์•Œ์•„๋ณด๊ณ , RxSwift์˜ Traits์— ๋Œ€ํ•ด ์ •๋ฆฌํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. (RxCocoa์˜ Traits๋Š” ๋‹ค์Œ ๊ฒŒ์‹œ๊ธ€์—์„œ ์ด์–ด์„œ ์ •๋ฆฌํ•˜๋„๋ก ํ• ๊ฒŒ์š”!) ์ด๋ฒˆ ๊ฒŒ์‹œ๊ธ€์€ ReactiveX/RxSwift์˜ Traits ๋ฌธ์„œ๋ฅผ ๋ฒˆ์—ญํ•˜๋ฉด์„œ Traits์— ๋Œ€ํ•ด ์ •๋ฆฌํ•ด๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. Traits๋ž€? Swift๋Š” ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ์ •ํ™•์„ฑ๊ณผ ์•ˆ์ •์„ฑ์„ ํ–ฅ์ƒ์‹œํ‚ค๊ณ  Rx ์‚ฌ์šฉ์„ ๋ณด๋‹ค ์ง๊ด€์ ์ด๊ณ  ๊ฐ„๋‹จํ•˜๊ฒŒ ๋งŒ๋“œ๋Š” ๋ฐ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ๊ฐ•๋ ฅํ•œ ์œ ํ˜• ์‹œ์Šคํ…œ์„ ๊ฐ–์ถ”๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. Traits๋Š” ์ธํ„ฐํŽ˜์ด์Šค ๊ฒฝ๊ณ„๋ฅผ ๋„˜์–ด ๊ด€์ฐฐ ๊ฐ€๋Šฅํ•œ ์‹œํ€€์Šค ์†์„ฑ์„ ์ „๋‹ฌํ•˜๊ณ  ๋ณด์žฅํ•˜๋Š” ๋ฐ ๋„์›€์ด ๋  ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ ๋ชจ๋“  ์ปจํ…์ŠคํŠธ์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ์›์‹œ Observable๊ณผ ๋น„๊ตํ•  ๋•Œ ๋ฌธ๋งฅ์ ์ธ ์˜๋ฏธ๋ฅผ ์ œ๊ณตํ•˜๊ณ  ๋” ๊ตฌ..
[RxSwift] Relay๋ž€? ์•ˆ๋…•ํ•˜์„ธ์š” ์ œ์ธ์ž…๋‹ˆ๋‹ค :) ์ €๋ฒˆ Rx ๊ฒŒ์‹œ๊ธ€์ด์—ˆ๋˜ Subject์— ์ด์–ด Relay์— ๋Œ€ํ•ด์„œ๋„ ํ•œ ๋ฒˆ ์ •๋ฆฌํ•ด๋ณด๋ ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค. ์ด๋ฒˆ์—๋„ RxSwift: Reactive Programming with Swift ์ฑ…์„ ์ฐธ๊ณ ํ•ด์„œ ์ •๋ฆฌ๋ฅผ ํ•ด๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค! Subject์— ๋Œ€ํ•ด ์ž˜ ๋ชจ๋ฅด์‹œ๊ฒ ๋‹ค๋ฉด ์•„๋ž˜์˜ ๊ฒŒ์‹œ๊ธ€์„ ๋จผ์ € ์ฝ๊ณ  ์˜ค์‹œ๋Š” ๊ฒƒ์„ ์ถ”์ฒœ๋“œ๋ฆฝ๋‹ˆ๋‹ค. [RxSwift] Subject๋ž€? ์•ˆ๋…•ํ•˜์„ธ์š” ์ œ์ธ์ž…๋‹ˆ๋‹ค : ) ์ฐธ ์˜ค๋žœ๋งŒ์— RxSwift ๊ฒŒ์‹œ๊ธ€ ์“ฐ๊ฒŒ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.. ๋ฌธ ๋‹ซ์€๊ฑฐ ์•„๋‹ˆ๊ตฌ์š” ์ •์ƒ์˜์—…ํ•˜๋ ค๊ตฌ์š”.. ๋„ค.. ์‚ฌ์‹ค ๊ทธ๋™์•ˆ RxSwift ๊ณต๋ถ€๋ฅผ ์•„์˜ˆ ์•ˆํ•œ ๊ฒƒ์€ ์•„๋‹Œ๋ฐ์š”.. ๋ญ”๊ฐ€ ๊ฒŒ์‹œ๊ธ€์„ ์“ธ ๋•Œ janechoi.tistory.com Relay๋ž€? Relay๋Š” Subject์˜ Wrapper ํด๋ž˜์Šค๋กœ, RxCocoa ๋‚ด๋ถ€์—..
[RxSwift] Subject๋ž€? ์•ˆ๋…•ํ•˜์„ธ์š” ์ œ์ธ์ž…๋‹ˆ๋‹ค : ) ์ฐธ ์˜ค๋žœ๋งŒ์— RxSwift ๊ฒŒ์‹œ๊ธ€ ์“ฐ๊ฒŒ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.. ๋ฌธ ๋‹ซ์€๊ฑฐ ์•„๋‹ˆ๊ตฌ์š” ์ •์ƒ์˜์—…ํ•˜๋ ค๊ตฌ์š”.. ๋„ค.. ์‚ฌ์‹ค ๊ทธ๋™์•ˆ RxSwift ๊ณต๋ถ€๋ฅผ ์•„์˜ˆ ์•ˆํ•œ ๊ฒƒ์€ ์•„๋‹Œ๋ฐ์š”.. ๋ญ”๊ฐ€ ๊ฒŒ์‹œ๊ธ€์„ ์“ธ ๋•Œ ํ™•์‹คํ•œ ์ •๋ณด๋ฅผ ์ „๋‹ฌํ•ด์•ผํ•œ๋‹ค๋Š” ์ƒ๊ฐ์— ์ข€ ๋” ๊ณต๋ถ€ํ•˜๊ณ  ์ •๋ฆฌํ•ด์„œ ์˜ฌ๋ฆฌ์ž ์ข€ ๋” ํ•˜๊ณ ... ํ•˜๋‹ค๊ฐ€ ์ด๋ ‡๊ฒŒ ๋ฏธ๋ฃจ๊ฒŒ ๋œ ๊ฒƒ ๊ฐ™๋„ค์š” ํ•˜ํ•ซ ์ด์ œ ๋” ์ด์ƒ ๋ฏธ๋ฃฐ ์ˆ˜ ์—†๋‹ค! ๋งŽ์ด ๋ถ€์กฑํ•ด๋„ ๊ธ€๋กœ ์ •๋ฆฌํ•˜๋ฉด์„œ ํ™•์‹คํžˆ ์ดํ•ดํ•˜๋Š” ๋ถ€๋ถ„๋“ค์ด ๋งŽ์€ ๊ฒƒ ๊ฐ™๊ธฐ๋„ ํ•˜๊ณ , ์ตœ๊ทผ์— ํ”„๋กœ์ ํŠธ์—์„œ RxSwift๋ฅผ ์ด์šฉํ•ด ๋น„๋™๊ธฐ ์ฒ˜๋ฆฌ๋ฅผ ํ•  ์ผ์ด ๋งŽ์€๋ฐ ์ •ํ™•ํžˆ ์•Œ์ง€ ๋ชปํ•˜๋Š” ๋ถ€๋ถ„์ด ๋งŽ๋‹ค๊ณ  ๋Š๊ผˆ์Šต๋‹ˆ๋‹ค.. ๊ทธ๋ž˜์„œ ์ œ๋Œ€๋กœ ์•Œ๊ณ  ์ฝ”๋“œ๋ฅผ ์งœ๊ณ  ์‹ถ์–ด์„œ ๋‹ค์‹œ RxSwift ๊ณต๋ถ€๋ฅผ ์—ด์‹ฌํžˆํ•˜๋ฉฐ ํ‹ฐ์Šคํ† ๋ฆฌ์—๋„ ์ •๋ฆฌ๋ฅผ ํ•ด๋ณด๋ ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค! ๋งˆ์ง€๋ง‰์œผ๋กœ Observabl..
[RxSwift] Observable RxSwift ๊ฐœ๋… ์ •๋ฆฌ๊ธ€์—์„œ RxSwift์˜ ์ •์˜์— ๋Œ€ํ•ด ์ •๋ฆฌํ•ด๋ณด๋ฉฐ, Observable์ด ๋ฐ˜์‘ํ˜•(Reactive) ํ”„๋กœ๊ทธ๋ž˜๋ฐ์˜ ๊ฐ€์žฅ ํฐ ํ•ต์‹ฌ์ด๋‹ค. ๋ผ๊ณ  ์ •๋ฆฌํ–ˆ์Šต๋‹ˆ๋‹ค. ๊ทธ๋ ‡๋‹ค๋ฉด ์ด ์ค‘์š”ํ•œ ๊ฐœ๋…! Observable์ด ๋ฌด์—‡์ธ์ง€, ์–ด๋–ป๊ฒŒ ๋งŒ๋“œ๋Š”์ง€, ์–ด๋–ป๊ฒŒ ์‚ฌ์šฉํ•˜๋Š”์ง€์— ๋Œ€ํ•ด์„œ ์ข€ ๋” ์ž์„ธํžˆ ์•Œ์•„๋ด…์‹œ๋‹ค! Observable Observable์˜ ๊ฐœ๋…๋ถ€ํ„ฐ ๋‹ค์‹œ ๊ฐ€์ ธ์™€์„œ ์„ค๋ช…ํ•ด๋ณด์ž๋ฉด, ReactiveX์—์„œ Observable ๊ฐ์ฒด๋Š” ์‚ฌ์ „์ ์ธ ์˜๋ฏธ๋Œ€๋กœ ์–ด๋–ค '๊ฐ์ฒด'๋ฅผ ๊ด€์ฐฐํ•  ์ˆ˜ ์žˆ๋Š” ํ˜•ํƒœ๋กœ ๋งŒ๋“œ๋Š” ๊ฒƒ์„ ๋งํ•˜๋ฉฐ, Observable ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•จ์œผ๋กœ์จ Observer๋Š” ๊ด€์ฐฐ์„ ์‹œ์ž‘(๊ตฌ๋…)ํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. ์ด '๊ฐ์ฒด'์— ๋”ฐ๋ผ ์‹ค์ œ ๊ด€์ฐฐํ•˜๋Š” ๊ฐ’(== ์ŠคํŠธ๋ฆผ์— ํ˜๋ ค๋ณด๋‚ด๋Š” ๊ฐ’) ํ˜น์€ ๊ด€์ฐฐ์˜ ๋Œ€์ƒ์ธ ์‚ฌ๊ฑด(== ์ด๋ฒคํŠธ)์ด ๊ฒฐ์ •๋ฉ๋‹ˆ..
[RxSwift] RxSwift์™€ ๋น„๋™๊ธฐ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์•ˆ๋…•ํ•˜์„ธ์š”! ์ œ์ธ์ž…๋‹ˆ๋‹ค :) ์š”์ฆ˜ ๋น„๋™๊ธฐ์  ์ฒ˜๋ฆฌ์— ๋Œ€ํ•œ ํ•„์š”์„ฑ์„ ๋Š๋ผ๊ณ , ์•„ํ‚คํ…์ฒ˜ ๊ณต๋ถ€๋„ ์‹œ์ž‘ํ•˜๋‹ค ๋ณด๋‹ˆ ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ RxSwift์— ๊ด€์‹ฌ์ด ์ƒ๊ฒจ ๊ณต๋ถ€๋ฅผ ํ•ด๋ณด๊ณ  ์žˆ๋Š”๋ฐ์š”! RxSwift์˜ ๊ธฐ๋ณธ ๊ฐœ๋…๋ถ€ํ„ฐ ์ฐจ๊ทผ์ฐจ๊ทผ ์ •๋ฆฌํ•ด๋‚˜๊ฐ€๋ ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค! RxSwift๋ž€? RxSwift๋Š” Reactive eXtension + Swift์˜ ํ•ฉ์„ฑ์–ด๋กœ ์ด๋ฃจ์–ด์ง„ ์šฉ์–ด๋กœ, Swift์— ReactiveX๋ฅผ ์ ์šฉ์‹œ์ผœ ๋น„๋™๊ธฐ ํ”„๋กœ๊ทธ๋ž˜๋ฐ์„ ์ง๊ด€์ ์œผ๋กœ ์ž‘์„ฑํ•  ์ˆ˜ ์žˆ๋„๋ก ๋„์™€์ฃผ๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์ž…๋‹ˆ๋‹ค. ๊ทธ๋ ‡๋‹ค๋ฉด ReactiveX๋ž€ ๋ฌด์—‡์ผ๊นŒ์š”?๐Ÿค” ReactiveX ๊ณต์‹ ํ™ˆํŽ˜์ด์ง€์— ๋”ฐ๋ฅด๋ฉด ReactiveX๋ž€, An API for asynchronous programming with observable streams '์˜ต์ €๋ฒ„๋ธ” ์ŠคํŠธ๋ฆผ์œผ๋กœ ๋น„๋™๊ธฐ ํ”„๋กœ๊ทธ๋ž˜๋ฐ์„ ..