Skip to content

Commit

Permalink
modify
Browse files Browse the repository at this point in the history
  • Loading branch information
maowangxin committed Nov 17, 2023
1 parent ad58954 commit e4e83c9
Show file tree
Hide file tree
Showing 5 changed files with 187 additions and 138 deletions.
Original file line number Diff line number Diff line change
@@ -1,53 +1,14 @@
{
"images" : [
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "29x29",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "29x29",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "40x40",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "40x40",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "60x60",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "60x60",
"scale" : "3x"
},
{
"idiom" : "ios-marketing",
"size" : "1024x1024",
"scale" : "1x"
"filename" : "WXNetworkingSwif_logo.png",
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
106 changes: 19 additions & 87 deletions Example/WXNetworkingSwift/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,24 @@ import WXNetworkingSwift
import MobileCoreServices
import Alamofire

class DKeywordListModel: Convertible {
var acm: String? = nil
var defaultKeyWord: String? = nil
class WXBannerModel: Convertible {
let sort: Int? = nil
let title: String? = nil
let acm: String? = nil
let image: String? = nil
let link: String? = nil
required init() {}
}

class DKeywordContextModel: Convertible {
var currentTime: String? = nil
var dataTime: String? = "20211117"
class WXContextModel: Convertible {
let currentTime: String? = nil
let dataTime: String? = "20211117"
required init() {}
}

class DKeywordModel: Convertible {
var nextPage: String = "zhangSan"
var isEnd: Int = 20
var context: DKeywordContextModel? = nil
var list: [DKeywordListModel]? = nil
class WXRecommendModel: Convertible {
let nextPage: String = "zhangSan"
let isEnd: Int = 20
let context: WXContextModel? = nil
let list: [WXBannerModel]? = nil
required init() {}
}

Expand Down Expand Up @@ -57,96 +58,27 @@ class ViewController: UIViewController {
}

@IBAction func requestButtonAction(_ sender: UIBarButtonItem) {
testBatchRequest()
testRequest()
}

//MARK: ----- 测试单个请求 -----
func testRequest() {
// let url = "https://httpbin.org/delay/5"
let url = "http://123.207.32.32:8000/home/multidata"
let api = WXRequestApi(url, method: .get)
api.timeOut = 40
api.loadingSuperView = view
api.requestSerializer = .EncodingFormURL
//api.autoCacheResponse = true
api.successStatusMap = (key: "returnCode", value: "SUCCESS")
api.parseModelMap = (parseKey: "data.dKeyword", modelType: DKeywordModel.self)
api.parseModelMap = (parseKey: "data.recommend", modelType: WXRecommendModel.self)
requestTask = api.startRequest { [weak self] responseModel in
self?.textView.text = responseModel.responseDict?.description
if let model = responseModel.parseKeyPathModel as? WXRecommendModel {
WXDebugLog("这个就是解析好的数据模型: \(model)")
}
}
}

func testRequestAFResponse() {
let boutiqueListNewURL = URL(string: "")

AF.request(boutiqueListNewURL as! URLRequestConvertible).response { (response:AFDataResponse) in
switch response.result {
case .success(let JSON):
do {
let JSONObject = try? JSONSerialization.jsonObject(with: JSON ?? Data(), options: .allowFragments)
if let JSON = JSONObject as? [String:Any] {
debugPrint(JSON.debugDescription)
let data = JSON["data"] as! [String:Any]
let returnData = data["returnData"] as! [String:Any]
let comicLists = returnData["comicLists"] as! NSArray
let comics = comicLists[0] as! [String:Any]
let itemTitle = comics["itemTitle"] as! String
debugPrint("itemTitle: \(itemTitle)")
}
}

case .failure(let error):
debugPrint(error)

}
}
}

func testRequestAFresponseJSON() {
// let boutiqueListNewURL = URL(string: "")
// AF.request(boutiqueListNewURL, method: .get).responseJSON {response in
// switch response.result {
// case .success(let value as [String: Any]):
// debugPrint("success: \(String(describing: value["code"]))")
// let data = value["data"] as! [String:Any]
// let returnData = data["returnData"] as! [String:Any]
// let comicLists = returnData["comicLists"] as! NSArray
// // let comics = comicLists[0] as! [String:Any]
// // let itemTitle = comics["itemTitle"] as! String
// //print("itemTitle: \(itemTitle)")
//
// self.comicList = comicLists.map { list in
// let item = ComicList()
// if let list = list as? [String:Any] {
// let comicsList = list["comics"] as? NSArray
// if comicsList?.count ?? 0 > 0 {
// let comics = comicsList?[0] as! [String:Any]
// item.itemTitle = comics["short_description"] as? String
// }
// }
// return item
// }
// self.tableView.reloadData()
//
// case .failure(let error):
// debugPrint("Failure: \(error)")
// default: fatalError("Fatal error.")
// }
// }
}

func testRequestAFresponseDecodable() {
// let boutiqueListNewURL = URL(string: "")
// AF.request(boutiqueListNewURL).responseDecodable(of: U17Root.self) { response in
// debugPrint("Response: \(response)")
// debugPrint("comicListsL Response: \(response.value?.data?.returnData?.comicLists?[0].itemTitle ?? "1000")")
//
// self.comicList = response.value?.data?.returnData?.comicLists
// self.tableView.reloadData()
// }
}


//MARK: ----- 测试批量请求 -----
func testBatchRequest() {
let url1 = "https://httpbin.org/get"
Expand Down
15 changes: 9 additions & 6 deletions Example/WXNetworkingSwift/WXLoadingHUD.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,17 @@ class WXLoadingHUD: UIView {

fileprivate func initSubView() {
backgroundColor = .clear
addSubview(imageView)
addSubview(indicatorView)
indicatorView.startAnimating()
}

lazy var imageView: UIImageView = {
let imageView = UIImageView(image: UIImage(named: "loading"))
imageView.frame = CGRect(x: 0, y: 0, width: 100, height: 100)
imageView.contentMode = .scaleAspectFit
return imageView
lazy var indicatorView: UIActivityIndicatorView = {
let indicatorView = UIActivityIndicatorView(style: .whiteLarge)
indicatorView.frame = CGRect(x: 0, y: 0, width: 100, height: 100)
indicatorView.color = .red
return indicatorView
}()



}
153 changes: 153 additions & 0 deletions Pods/Alamofire/Source/RequestCompression.swift

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e4e83c9

Please sign in to comment.