Commit 83b85986 authored by pete谢兆麟's avatar pete谢兆麟

rxswift service层demo

parent 165a352f
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
objects = { objects = {
/* Begin PBXBuildFile section */ /* Begin PBXBuildFile section */
0468D41D2B47D20600CFB916 /* YHHomeNetWorkServer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0468D41C2B47D20600CFB916 /* YHHomeNetWorkServer.swift */; };
04808C062B4686510056D53C /* ATAuthSDK.bundle in Resources */ = {isa = PBXBuildFile; fileRef = 04808C042B4686510056D53C /* ATAuthSDK.bundle */; }; 04808C062B4686510056D53C /* ATAuthSDK.bundle in Resources */ = {isa = PBXBuildFile; fileRef = 04808C042B4686510056D53C /* ATAuthSDK.bundle */; };
04808C072B4686C10056D53C /* ATAuthSDK_D.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 04808C032B4686510056D53C /* ATAuthSDK_D.framework */; }; 04808C072B4686C10056D53C /* ATAuthSDK_D.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 04808C032B4686510056D53C /* ATAuthSDK_D.framework */; };
04808C082B4686C10056D53C /* ATAuthSDK_D.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 04808C032B4686510056D53C /* ATAuthSDK_D.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 04808C082B4686C10056D53C /* ATAuthSDK_D.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 04808C032B4686510056D53C /* ATAuthSDK_D.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
...@@ -103,6 +104,7 @@ ...@@ -103,6 +104,7 @@
/* End PBXCopyFilesBuildPhase section */ /* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */ /* Begin PBXFileReference section */
0468D41C2B47D20600CFB916 /* YHHomeNetWorkServer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHHomeNetWorkServer.swift; sourceTree = "<group>"; };
04808C032B4686510056D53C /* ATAuthSDK_D.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = ATAuthSDK_D.framework; sourceTree = "<group>"; }; 04808C032B4686510056D53C /* ATAuthSDK_D.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = ATAuthSDK_D.framework; sourceTree = "<group>"; };
04808C042B4686510056D53C /* ATAuthSDK.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; path = ATAuthSDK.bundle; sourceTree = "<group>"; }; 04808C042B4686510056D53C /* ATAuthSDK.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; path = ATAuthSDK.bundle; sourceTree = "<group>"; };
58C2405158A4A6632D0E7460 /* Pods-galaxy.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-galaxy.debug.xcconfig"; path = "Target Support Files/Pods-galaxy/Pods-galaxy.debug.xcconfig"; sourceTree = "<group>"; }; 58C2405158A4A6632D0E7460 /* Pods-galaxy.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-galaxy.debug.xcconfig"; path = "Target Support Files/Pods-galaxy/Pods-galaxy.debug.xcconfig"; sourceTree = "<group>"; };
...@@ -202,6 +204,14 @@ ...@@ -202,6 +204,14 @@
/* End PBXFrameworksBuildPhase section */ /* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */ /* Begin PBXGroup section */
0468D41B2B47D1E500CFB916 /* Server */ = {
isa = PBXGroup;
children = (
0468D41C2B47D20600CFB916 /* YHHomeNetWorkServer.swift */,
);
path = Server;
sourceTree = "<group>";
};
04808C022B4686510056D53C /* Frameworks */ = { 04808C022B4686510056D53C /* Frameworks */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
...@@ -527,6 +537,7 @@ ...@@ -527,6 +537,7 @@
A5ACE9592B457113002C94D2 /* Home(首页) */ = { A5ACE9592B457113002C94D2 /* Home(首页) */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
0468D41B2B47D1E500CFB916 /* Server */,
A5D6AB192B465DFF001C10A5 /* VM */, A5D6AB192B465DFF001C10A5 /* VM */,
A5ACE95C2B457133002C94D2 /* C */, A5ACE95C2B457133002C94D2 /* C */,
A5ACE95B2B45712D002C94D2 /* V */, A5ACE95B2B45712D002C94D2 /* V */,
...@@ -781,6 +792,7 @@ ...@@ -781,6 +792,7 @@
A5ACE94C2B4564F7002C94D2 /* BsHUDErrorView.swift in Sources */, A5ACE94C2B4564F7002C94D2 /* BsHUDErrorView.swift in Sources */,
A5D6AB1B2B46A1CC001C10A5 /* YHHomeModel.swift in Sources */, A5D6AB1B2B46A1CC001C10A5 /* YHHomeModel.swift in Sources */,
A5D6AB1D2B46AAFB001C10A5 /* YHHomePageViewModel.swift in Sources */, A5D6AB1D2B46AAFB001C10A5 /* YHHomePageViewModel.swift in Sources */,
0468D41D2B47D20600CFB916 /* YHHomeNetWorkServer.swift in Sources */,
A5ACE9552B4564F7002C94D2 /* YHTabBarViewController.swift in Sources */, A5ACE9552B4564F7002C94D2 /* YHTabBarViewController.swift in Sources */,
A5ACE9402B4564F7002C94D2 /* String+Extension.swift in Sources */, A5ACE9402B4564F7002C94D2 /* String+Extension.swift in Sources */,
A5ACE9482B4564F7002C94D2 /* BsHUDWariningView.swift in Sources */, A5ACE9482B4564F7002C94D2 /* BsHUDWariningView.swift in Sources */,
......
...@@ -43,7 +43,7 @@ class YHHomeViewController: YHBaseViewController { ...@@ -43,7 +43,7 @@ class YHHomeViewController: YHBaseViewController {
} }
private func bind() { private func bind() {
homeReqVM.subject.subscribe(onNext: { model in homeReqVM.subject.observe(on: MainScheduler.instance).subscribe(onNext: { model in
}).disposed(by: disposeBag) }).disposed(by: disposeBag)
} }
......
//
// YHHomeNetWorkServer.swift
// galaxy
//
// Created by EDY on 2024/1/5.
// Copyright © 2024 www.davidhuang.com. All rights reserved.
//
import UIKit
import RxSwift
class YHHomeNetWorkServer {
static let share = YHHomeNetWorkServer()
func getRequest(_ url: String) -> Single<[String: Any]> {
return Single<[String: Any]>.create { single in
YHNetRequest.getRequest(url: url) { json, code in
//1. json字符串 转 对象
guard let model = NetBaseModel.deserialize(dict: json) else {
print("error....底层解析出错了...")
return single(.failure(YHError.net))
}
return single(.success(json))
} failBlock: { err in
return single(.failure(YHError.net))
} as! any Disposable
}
}
}
enum YHError: Error {
case net
case fail
}
...@@ -10,6 +10,8 @@ import UIKit ...@@ -10,6 +10,8 @@ import UIKit
import RxSwift import RxSwift
class YHHomePageViewModel { class YHHomePageViewModel {
let service = YHHomeNetWorkServer.share
let disposeBag = DisposeBag()
//数据源 //数据源
var configModel:YHHomeCofigMode? var configModel:YHHomeCofigMode?
let subject = PublishSubject<YHHomeCofigMode>() let subject = PublishSubject<YHHomeCofigMode>()
...@@ -32,4 +34,13 @@ extension YHHomePageViewModel { ...@@ -32,4 +34,13 @@ extension YHHomePageViewModel {
print(err) print(err)
} }
} }
func getRxHomeConfig() {
let strUrl = YHBaseUrlManager.shared.curURL() + YHAllApiName.Common.homeConfigApi
service.getRequest(strUrl).subscribe { jsno in
self.subject.onNext(YHHomeCofigMode())
} onFailure: { error in
}.disposed(by: disposeBag)
}
} }
...@@ -212,6 +212,7 @@ extension YHNetRequest { ...@@ -212,6 +212,7 @@ extension YHNetRequest {
} }
class func postRequest(url:String, params:[String:Any] = [:], successBlock: SuccessHandlerType!, failBlock: FailureHandlerType!) -> Request? { class func postRequest(url:String, params:[String:Any] = [:], successBlock: SuccessHandlerType!, failBlock: FailureHandlerType!) -> Request? {
YHLOG(message:"\n发起请求的URL是===> url = \(url)")
return YHNetRequest().url(url).requestType(.post).success(successBlock).failed(failBlock).startRequest() return YHNetRequest().url(url).requestType(.post).success(successBlock).failed(failBlock).startRequest()
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment