优惠券swift版马甲包

XLDemo.swift 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. //
  2. // XLDemo.swift
  3. // YLBaseComponent
  4. //
  5. // Created by chenxiaofeng on 2018/8/29.
  6. // Copyright © 2018年 xuanlv.cgs.com. All rights reserved.
  7. //
  8. import Foundation
  9. import RxSwift
  10. import Moya
  11. import ObjectMapper
  12. import NSObject_Rx
  13. import Result
  14. enum XLTestApi {
  15. case home
  16. case user
  17. }
  18. extension XLTestApi: XLTargetType{
  19. var path: String {
  20. switch self {
  21. case .home:
  22. return "/home"
  23. case .user:
  24. return "/user"
  25. }
  26. }
  27. var parameters: [String : Any]? {
  28. switch self {
  29. case .home:
  30. return ["id" : 23]
  31. case .user:
  32. return ["id" : 23]
  33. }
  34. }
  35. }
  36. class XLTest {
  37. let provider = XLProvider<XLTestApi>()
  38. func requestUser(){
  39. // 调用
  40. let provider = XLProvider<XLTestApi>()
  41. let userSequence = provider.rx.requestResult(.user) as Observable<XLRequestResult<XLTestModel>>
  42. // 1
  43. provider.rx.requestModel(.home).subscribe(onSuccess: { (model:XLTestModel, isCache:Bool) in
  44. }) { (error) in
  45. }.disposed(by: disposeBag)
  46. // 2
  47. // 3
  48. provider.rx.requestResult(.user).subscribe(onNext: { (result:Result<XLTestModel, AnyError> , isCache:Bool) in
  49. switch result {
  50. case .success(let model):
  51. break
  52. case .failure(let error):
  53. let err = error.error
  54. }
  55. }).disposed(by: disposeBag)
  56. }
  57. }
  58. extension XLTest: HasDisposeBag {}
  59. struct XLTestModel: Mappable {
  60. var name: String = ""
  61. var age: Int = 0
  62. var gender: Int = 0
  63. init?(map: Map) {
  64. }
  65. mutating func mapping(map: Map) {
  66. name <- map["name"]
  67. age <- map["age"]
  68. gender <- map["sex"]
  69. }
  70. }