Upgrade to Pro — share decks privately, control downloads, hide ads and more …

RxSwift 시작하기

RxSwift 시작하기

Suyeol Jeon

October 27, 2017
Tweet

More Decks by Suyeol Jeon

Other Decks in Programming

Transcript

  1. a = 10 b = a * 2 print(b) //

    20 a = 30 print(b)
  2. a = 10 b = a * 2 print(b) //

    20 a = 30 print(b) // 20
  3. a = 10 b = a * 2 print(b) //

    20 a = 30 print(b) // 20 60
  4. ࣽࣻ ೣࣻ • ࠗ੘ਊਸ ߊࢤदః૑ ঋח ೣࣻ • ଵઑ ైݺࢿ੉

    ੓ח ೣࣻ ೣࣻ झ௏೐ܳ ߩযաࢲ ߄Ӵ ࣁ࢚ী ߸ചܳ оೞח ೯ز (࢚క ߸҃, ֎౟ਕఊ, I/O ١)
  5. ࣽࣻ ೣࣻ • ࠗ੘ਊਸ ߊࢤदః૑ ঋח ೣࣻ • ଵઑ ైݺࢿ੉

    ੓ח ೣࣻ ੑ۱੉ زੌೞ׮ݶ ୹۱ب ೦࢚ زੌ
  6. var rate = 1130 func krw(usd: Int) -> Int {

    return usd * rate } krw(usd: 2) // 2260 krw(usd: 3) // 3390
  7. var rate = 1130 func krw(usd: Int) -> Int {

    return usd * rate } rate = 1140 krw(usd: 2) // 2260 krw(usd: 3) // 3390
  8. var rate = 1130 func krw(usd: Int) -> Int {

    return usd * rate } rate = 1140 krw(usd: 2) // 2260 2280 krw(usd: 3) // 3390 3420
  9. var rate = 1130 func krw(usd: Int) -> Int {

    return usd * rate } ੹৉ ࢚కী ੄ઓ rate = 1140 krw(usd: 2) // 2260 2280 krw(usd: 3) // 3390 3420
  10. var rate = 1130 func krw(usd: Int) -> Int {

    return usd * rate } ੹৉ ࢚కী ੄ઓ rate = 1140 krw(usd: 2) // 2260 2280 krw(usd: 3) // 3390 3420 ଵઑ ైݺࢿ੉ হ׮
  11. a b

  12. 10 20 30 40 a 20 40 60 80 b

    map(x => x * 2)
  13. 10 20 30 40 a 20 40 60 80 b

    map(x => x * 2) Marble Diagrams
  14. 20 40 60 80 b map(x => x * 2)

    Observable.from([10, 20, 30, 40])
  15. Observable.from([10, 20, 30, 40]) .map { $0 * 2 }

    .subscribe(onNext: { value in print(value) })
  16. Observable.from([10, 20, 30, 40]) .map { $0 * 2 }

    .subscribe(onNext: { value in print(value) })
  17. Observable.from([10, 20, 30, 40]) .map { $0 * 2 }

    .subscribe(onNext: { value in print(value) })
  18. Observable.from([10, 20, 30, 40]) .map { $0 * 2 }

    .subscribe(onNext: { value in print(value) // 20 })
  19. Observable.from([10, 20, 30, 40]) .map { $0 * 2 }

    .subscribe(onNext: { value in print(value) })
  20. Observable.from([10, 20, 30, 40]) .map { $0 * 2 }

    .subscribe(onNext: { value in print(value) })
  21. Observable.from([10, 20, 30, 40]) .map { $0 * 2 }

    .subscribe(onNext: { value in print(value) // 40 })
  22. Observable.from([10, 20, 30, 40]) .map { $0 * 2 }

    .subscribe(onNext: { value in print(value) })
  23. Observable.from([10, 20, 30, 40]) .map { $0 * 2 }

    .subscribe(onNext: { value in print(value) })
  24. Observable.from([10, 20, 30, 40]) .map { $0 * 2 }

    .subscribe(onNext: { value in print(value) // 60 })
  25. Observable.from([10, 20, 30, 40]) .map { $0 * 2 }

    .subscribe(onNext: { value in print(value) })
  26. Observable.from([10, 20, 30, 40]) .map { $0 * 2 }

    .subscribe(onNext: { value in print(value) })
  27. Observable.from([10, 20, 30, 40]) .map { $0 * 2 }

    .subscribe(onNext: { value in print(value) // 80 })
  28. Observable.from([10, 20, 30, 40]) .map { $0 * 2 }

    .subscribe(onNext: { value in print(value) // 80 }) Observable
  29. Observable.from([10, 20, 30, 40]) .map { $0 * 2 }

    .subscribe(onNext: { value in print(value) // 80 }) Observer
  30. "1" false map(str => str.length >= 4) "❌ " map(valid

    => getMessage(valid)) ੑ۱ ݫद૑
  31. "1" "12" false map(str => str.length >= 4) "❌ "

    map(valid => getMessage(valid)) ੑ۱ ݫद૑
  32. "1" "12" false false map(str => str.length >= 4) "❌

    " map(valid => getMessage(valid)) ੑ۱ ݫद૑
  33. "1" "12" false false map(str => str.length >= 4) "❌

    " "❌ " map(valid => getMessage(valid)) ੑ۱ ݫद૑
  34. "1" "12" "123" false false map(str => str.length >= 4)

    "❌ " "❌ " map(valid => getMessage(valid)) ੑ۱ ݫद૑
  35. "1" "12" "123" false false false map(str => str.length >=

    4) "❌ " "❌ " map(valid => getMessage(valid)) ੑ۱ ݫद૑
  36. "1" "12" "123" false false false map(str => str.length >=

    4) "❌ " "❌ " "❌ " map(valid => getMessage(valid)) ੑ۱ ݫद૑
  37. "1" "12" "123" "1234" false false false map(str => str.length

    >= 4) "❌ " "❌ " "❌ " map(valid => getMessage(valid)) ੑ۱ ݫद૑
  38. "1" "12" "123" "1234" false false false true map(str =>

    str.length >= 4) "❌ " "❌ " "❌ " map(valid => getMessage(valid)) ੑ۱ ݫद૑
  39. false false false true map(str => str.length >= 4) map(valid

    => getMessage(valid)) "1" "12" "123" "1234" ੑ۱ "❌ " "❌ " "❌ " "" ݫद૑
  40. passwordField.rx.text.orEmpty .map { $0.characters.count >= 4 } .map { isValid

    in if isValid { return "ࢎਊ оמೠ ࠺޻ߣഐੑפ׮. " } else { return "࠺޻ߣഐо ցޖ ૣणפ׮. ❌" } }
  41. passwordField.rx.text.orEmpty .map { $0.characters.count >= 4 } .map { isValid

    in if isValid { return "ࢎਊ оמೠ ࠺޻ߣഐੑפ׮. " } else { return "࠺޻ߣഐо ցޖ ૣणפ׮. ❌" } } .subscribe(onNext: { [weak self] message in self?.messageLabel.rx.text = message })
  42. passwordField.rx.text.orEmpty .map { $0.characters.count >= 4 } .map { isValid

    in if isValid { return "ࢎਊ оמೠ ࠺޻ߣഐੑפ׮. " } else { return "࠺޻ߣഐо ցޖ ૣणפ׮. ❌" } } .subscribe(onNext: { [weak self] message in self?.messageLabel.rx.text = message }) "1"
  43. passwordField.rx.text.orEmpty .map { $0.characters.count >= 4 } .map { isValid

    in if isValid { return "ࢎਊ оמೠ ࠺޻ߣഐੑפ׮. " } else { return "࠺޻ߣഐо ցޖ ૣणפ׮. ❌" } } .subscribe(onNext: { [weak self] message in self?.messageLabel.rx.text = message }) false
  44. passwordField.rx.text.orEmpty .map { $0.characters.count >= 4 } .map { isValid

    in if isValid { return "ࢎਊ оמೠ ࠺޻ߣഐੑפ׮. " } else { return "࠺޻ߣഐо ցޖ ૣणפ׮. ❌" } } .subscribe(onNext: { [weak self] message in self?.messageLabel.rx.text = message })
  45. passwordField.rx.text.orEmpty .map { $0.characters.count >= 4 } .map { isValid

    in if isValid { return "ࢎਊ оמೠ ࠺޻ߣഐੑפ׮. " } else { return "࠺޻ߣഐо ցޖ ૣणפ׮. ❌" } } .subscribe(onNext: { [weak self] message in self?.messageLabel.rx.text = message })
  46. passwordField.rx.text.orEmpty .map { $0.characters.count >= 4 } .map { isValid

    in if isValid { return "ࢎਊ оמೠ ࠺޻ߣഐੑפ׮. " } else { return "࠺޻ߣഐо ցޖ ૣणפ׮. ❌" } } .subscribe(onNext: { [weak self] message in self?.messageLabel.rx.text = message }) "12"
  47. passwordField.rx.text.orEmpty .map { $0.characters.count >= 4 } .map { isValid

    in if isValid { return "ࢎਊ оמೠ ࠺޻ߣഐੑפ׮. " } else { return "࠺޻ߣഐо ցޖ ૣणפ׮. ❌" } } .subscribe(onNext: { [weak self] message in self?.messageLabel.rx.text = message }) false
  48. passwordField.rx.text.orEmpty .map { $0.characters.count >= 4 } .map { isValid

    in if isValid { return "ࢎਊ оמೠ ࠺޻ߣഐੑפ׮. " } else { return "࠺޻ߣഐо ցޖ ૣणפ׮. ❌" } } .subscribe(onNext: { [weak self] message in self?.messageLabel.rx.text = message })
  49. passwordField.rx.text.orEmpty .map { $0.characters.count >= 4 } .map { isValid

    in if isValid { return "ࢎਊ оמೠ ࠺޻ߣഐੑפ׮. " } else { return "࠺޻ߣഐо ցޖ ૣणפ׮. ❌" } } .subscribe(onNext: { [weak self] message in self?.messageLabel.rx.text = message })
  50. passwordField.rx.text.orEmpty .map { $0.characters.count >= 4 } .map { isValid

    in if isValid { return "ࢎਊ оמೠ ࠺޻ߣഐੑפ׮. " } else { return "࠺޻ߣഐо ցޖ ૣणפ׮. ❌" } } .subscribe(onNext: { [weak self] message in self?.messageLabel.rx.text = message }) "123"
  51. passwordField.rx.text.orEmpty .map { $0.characters.count >= 4 } .map { isValid

    in if isValid { return "ࢎਊ оמೠ ࠺޻ߣഐੑפ׮. " } else { return "࠺޻ߣഐо ցޖ ૣणפ׮. ❌" } } .subscribe(onNext: { [weak self] message in self?.messageLabel.rx.text = message }) false
  52. passwordField.rx.text.orEmpty .map { $0.characters.count >= 4 } .map { isValid

    in if isValid { return "ࢎਊ оמೠ ࠺޻ߣഐੑפ׮. " } else { return "࠺޻ߣഐо ցޖ ૣणפ׮. ❌" } } .subscribe(onNext: { [weak self] message in self?.messageLabel.rx.text = message })
  53. passwordField.rx.text.orEmpty .map { $0.characters.count >= 4 } .map { isValid

    in if isValid { return "ࢎਊ оמೠ ࠺޻ߣഐੑפ׮. " } else { return "࠺޻ߣഐо ցޖ ૣणפ׮. ❌" } } .subscribe(onNext: { [weak self] message in self?.messageLabel.rx.text = message })
  54. passwordField.rx.text.orEmpty .map { $0.characters.count >= 4 } .map { isValid

    in if isValid { return "ࢎਊ оמೠ ࠺޻ߣഐੑפ׮. " } else { return "࠺޻ߣഐо ցޖ ૣणפ׮. ❌" } } .subscribe(onNext: { [weak self] message in self?.messageLabel.rx.text = message }) "1234"
  55. passwordField.rx.text.orEmpty .map { $0.characters.count >= 4 } .map { isValid

    in if isValid { return "ࢎਊ оמೠ ࠺޻ߣഐੑפ׮. " } else { return "࠺޻ߣഐо ցޖ ૣणפ׮. ❌" } } .subscribe(onNext: { [weak self] message in self?.messageLabel.rx.text = message }) true
  56. passwordField.rx.text.orEmpty .map { $0.characters.count >= 4 } .map { isValid

    in if isValid { return "ࢎਊ оמೠ ࠺޻ߣഐੑפ׮. " } else { return "࠺޻ߣഐо ցޖ ૣणפ׮. ❌" } } .subscribe(onNext: { [weak self] message in self?.messageLabel.rx.text = message })
  57. passwordField.rx.text.orEmpty .map { $0.characters.count >= 4 } .map { isValid

    in if isValid { return "ࢎਊ оמೠ ࠺޻ߣഐੑפ׮. " } else { return "࠺޻ߣഐо ցޖ ૣणפ׮. ❌" } } .subscribe(onNext: { [weak self] message in self?.messageLabel.rx.text = message })
  58. ࢎਊ੗ ੋఠۑ࣌ਸ ؘ੉ఠ ൒ܴਵ۽ ಴അ оמ Ӗ੗ ੑ۱: Observable<String> ं੗

    ੑ۱: Observable<Int> ߡౡ ఠ஖: Observable<Void> झ௼܀: Observable<CGPoint> ...
  59. "1"

  60. nicknameField.rx.text.orEmpty .flatMap { nickname -> Observable<Bool> in return API.checkNickname(nickname) }

    .map { isAvailable in return getMessage(isAvailable) } .subscribe(onNext: { [weak self] message in self?.messageLabel.text = message })
  61. nicknameField.rx.text.orEmpty .flatMap { nickname -> Observable<Bool> in return API.checkNickname(nickname) }

    .map { isAvailable in return getMessage(isAvailable) } .subscribe(onNext: { [weak self] message in self?.messageLabel.text = message })
  62. nicknameField.rx.text.orEmpty .debounce(0.3, scheduler: MainScheduler.instance) .flatMap { nickname -> Observable<Bool> in

    return API.checkNickname(nickname) } .map { isAvailable in return getMessage(isAvailable) } .subscribe(onNext: { [weak self] message in self?.messageLabel.text = message })
  63. Timer 00:17 var disposeBag = DisposeBag() Observable<Int> .interval(1, scheduler: ...)

    .subscribe(onNext: { tick in print(tick) }) .disposed(by: disposeBag)
  64. Timer 00:17 var disposeBag = DisposeBag() Observable<Int> .interval(1, scheduler: ...)

    .subscribe(onNext: { tick in print(tick) }) .disposed(by: disposeBag)
  65. var disposeBag = DisposeBag() Observable<Int> .interval(1, scheduler: ...) .subscribe(onNext: {

    tick in print(tick) }) .disposed(by: disposeBag) Start ݫݽܻীࢲ ೧ઁ
  66. var disposeBag = DisposeBag() Observable<Int> .interval(1, scheduler: ...) .subscribe(onNext: {

    tick in print(tick) }) .disposed(by: disposeBag) Start Dispose
  67. • ࢎਊ੗ ੋఠۑ࣌ਸ ؘ੉ఠ ൒ܴਵ۽ ୊ܻ • ӈଳ਷ ࢚క ҙܻܳ

    ࣚऔѱ • ࠺زӝ ௏٘ܳ ాੌػ ߑधਵ۽ ࢎਊ RxSwift