Flexible Networking in Swift.

Flexible Networking in Swift.

Tips and tricks for using Moya in a flexible manner. Recording stubs, auth token problems and some history included.

2ddf3bc5f8500fa7ae37cc364e662309?s=128

Sunshinejr

June 23, 2016
Tweet

Transcript

  1. NETWORKING IN SWIFT FLEXIBLE sunshinejr thesunshinejr

  2. Before Swift After WWDC’14 NETWORKING TIMELINE WWDC 2014 2 +

  3. BEFORE SWIFT 3

  4. NSURLCONNECTION AFNETWORKING NSURLSESSION 4

  5. 5

  6. WITH SWIFT 6

  7. NSURLSESSION ALAMOFIRE MOYA? 7

  8. MOYA 8 https://github.com/Moya/Moya

  9. 9

  10. EASY TESTING + FLEXIBILITY + OPTIONAL<REACTIVE EXTENSIONS> = + COMMUNITY

    10
  11. BASIC SETUP - TARGET + 11

  12. BASIC SETUP - RUN! 12

  13. MOYA+MAPPERS MOYA-OBJECTMAPPER MOYA-SWIFTYJSONMAPPER MOYA-ARGO MOYA-MODELMAPPER MOYA-GLOSS MOYA-JASON 13

  14. TIME FOR FLEXIN’ 14

  15. PROBLEM 1: PASSING AUTH TOKEN 15

  16. + 16

  17. PROBLEM 2: PASSING AUTH TOKEN … BUT SOMETIMES IN HEADERS

    … AND SOMETIMES IN PARAMETERS … AND SOMETIMES DON’T SEND IT AT ALL … AND SOMETIMES SEND GUEST TOKEN 17
  18. None
  19. + + 19

  20. + 20

  21. + 20

  22. + 20

  23. + 20

  24. None
  25. PROBLEM 3: API WITHOUT API 22

  26. SOLUTION: STUBS STUBS RECORDING + (warning: works only for simulator)

    23
  27. 1. BASH SCRIPT 24

  28. 2. RECORDING PLUGIN 25

  29. 3. STUBBABLE TARGET TYPE 26

  30. 3. STUBBABLE TARGET TYPE 26

  31. 3. STUBBABLE TARGET TYPE 26

  32. 3. STUBBABLE TARGET TYPE 26

  33. 3. STUBBABLE TARGET TYPE 26

  34. 4. CONFORM TO NEW TARGET TYPE 27

  35. 4. CONFORM TO NEW TARGET TYPE 27

  36. 4. CONFORM TO NEW TARGET TYPE 27

  37. 4. CONFORM TO NEW TARGET TYPE 27

  38. 4. CONFORM TO NEW TARGET TYPE 27

  39. 5. ADD PLUGIN TO MOYA PROVIDER OR 28

  40. QUESTIONS? https://github.com/sunshinejr/FlexibleMoya Code from slides at: More examples: https://github.com/Moya/Moya/tree/master/docs/Examples My

    Moya + RxSwift Networking tutorial: http://www.thedroidsonroids.com/blog/ios/rxswift-examples-3-networking/ sunshinejr thesunshinejr