Skip to content

Commit

Permalink
update the readme file
Browse files Browse the repository at this point in the history
  • Loading branch information
CNKCQ committed Dec 21, 2017
1 parent f73e62d commit 4f87dab
Show file tree
Hide file tree
Showing 1,894 changed files with 218 additions and 49 deletions.
10 changes: 7 additions & 3 deletions Example/AlamofireCodable.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
607FACEC1AFB9204008FA782 /* Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 607FACEB1AFB9204008FA782 /* Tests.swift */; };
70266E3656D15EB88DDDE359 /* Pods_AlamofireCodable_Tests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F4C98DA776AB542D7F2462D8 /* Pods_AlamofireCodable_Tests.framework */; };
7160B165E2A7296EFFD17872 /* Pods_AlamofireCodable_Example.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 31B2DD8247F140C55B05ADA8 /* Pods_AlamofireCodable_Example.framework */; };
AA8CAEAE1FC80C8B00F81A0E /* AURLProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA8CAEAD1FC80C8B00F81A0E /* AURLProtocol.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand All @@ -28,8 +29,8 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
00F0405AB685D185798E3EF4 /* README.md */ = {isa = PBXFileReference; includeInIndex = 1; name = README.md; path = ../README.md; sourceTree = "<group>"; };
28135418C057CE92C1DBF42D /* LICENSE */ = {isa = PBXFileReference; includeInIndex = 1; name = LICENSE; path = ../LICENSE; sourceTree = "<group>"; };
00F0405AB685D185798E3EF4 /* README.md */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = "<group>"; };
28135418C057CE92C1DBF42D /* LICENSE */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = LICENSE; path = ../LICENSE; sourceTree = "<group>"; };
2DFB02704A483B242DB77DAF /* Pods-AlamofireCodable_Example.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-AlamofireCodable_Example.release.xcconfig"; path = "Pods/Target Support Files/Pods-AlamofireCodable_Example/Pods-AlamofireCodable_Example.release.xcconfig"; sourceTree = "<group>"; };
31B2DD8247F140C55B05ADA8 /* Pods_AlamofireCodable_Example.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_AlamofireCodable_Example.framework; sourceTree = BUILT_PRODUCTS_DIR; };
607FACD01AFB9204008FA782 /* AlamofireCodable_Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = AlamofireCodable_Example.app; sourceTree = BUILT_PRODUCTS_DIR; };
Expand All @@ -43,9 +44,10 @@
607FACEA1AFB9204008FA782 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
607FACEB1AFB9204008FA782 /* Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Tests.swift; sourceTree = "<group>"; };
70CF63D0168E24E6B44B5094 /* Pods-AlamofireCodable_Tests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-AlamofireCodable_Tests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-AlamofireCodable_Tests/Pods-AlamofireCodable_Tests.debug.xcconfig"; sourceTree = "<group>"; };
AA8CAEAD1FC80C8B00F81A0E /* AURLProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AURLProtocol.swift; sourceTree = "<group>"; };
AEEC4C43C6C97A2A89328404 /* Pods-AlamofireCodable_Tests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-AlamofireCodable_Tests.release.xcconfig"; path = "Pods/Target Support Files/Pods-AlamofireCodable_Tests/Pods-AlamofireCodable_Tests.release.xcconfig"; sourceTree = "<group>"; };
D4F3EB5DFAC7F136EE98EB98 /* Pods-AlamofireCodable_Example.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-AlamofireCodable_Example.debug.xcconfig"; path = "Pods/Target Support Files/Pods-AlamofireCodable_Example/Pods-AlamofireCodable_Example.debug.xcconfig"; sourceTree = "<group>"; };
E0EFAF618EDA12B2BF2D74D0 /* AlamofireCodable.podspec */ = {isa = PBXFileReference; includeInIndex = 1; name = AlamofireCodable.podspec; path = ../AlamofireCodable.podspec; sourceTree = "<group>"; };
E0EFAF618EDA12B2BF2D74D0 /* AlamofireCodable.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = AlamofireCodable.podspec; path = ../AlamofireCodable.podspec; sourceTree = "<group>"; };
F4C98DA776AB542D7F2462D8 /* Pods_AlamofireCodable_Tests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_AlamofireCodable_Tests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -99,6 +101,7 @@
607FACDC1AFB9204008FA782 /* Images.xcassets */,
607FACDE1AFB9204008FA782 /* LaunchScreen.xib */,
607FACD31AFB9204008FA782 /* Supporting Files */,
AA8CAEAD1FC80C8B00F81A0E /* AURLProtocol.swift */,
);
name = "Example for AlamofireCodable";
path = AlamofireCodable;
Expand Down Expand Up @@ -381,6 +384,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
AA8CAEAE1FC80C8B00F81A0E /* AURLProtocol.swift in Sources */,
607FACD81AFB9204008FA782 /* ViewController.swift in Sources */,
607FACD61AFB9204008FA782 /* AppDelegate.swift in Sources */,
);
Expand Down
37 changes: 37 additions & 0 deletions Example/AlamofireCodable/AURLProtocol.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//
// URLProtocol.swift
// AlamofireCodable_Example
//
// Created by Steve on 24/11/2017.
// Copyright © 2017 CocoaPods. All rights reserved.
//

import Foundation

class AURLProtocol: URLProtocol {

static var session: URLSession!

struct PropertyKeys {
static let handledByForwarderURLProtocol = "HandledByProxyURLProtocol"
}

var activeTask: URLSessionTask?

override class func canInit(with request: URLRequest) -> Bool {
return true
}

override class func canonicalRequest(for request: URLRequest) -> URLRequest {
return request
}

override func startLoading() {
super.startLoading()
}

override func stopLoading() {
activeTask?.cancel()
}

}
1 change: 1 addition & 0 deletions Example/AlamofireCodable/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
URLProtocol.registerClass(AURLProtocol.self)
return true
}

Expand Down
98 changes: 75 additions & 23 deletions Example/AlamofireCodable/ViewController.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

//
// ViewController.swift
// AlamofireCodable
Expand All @@ -11,10 +12,19 @@ import AlamofireCodable
import Alamofire

class ViewController: UIViewController {

var manager: Alamofire.SessionManager = .default

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
// let configuration = NSURLSessionConfiguration.defaultSessionConfiguration()
// configuration.protocolClasses!.insert(MyURLProtocol.self, atIndex: 0)
// manager = Manager(configuration: configuration)
let configuration = URLSessionConfiguration.default
// URLProtocol.registerClass(AURLProtocol.self)
configuration.protocolClasses?.insert(AURLProtocol.self, at: 0)
manager = Alamofire.SessionManager(configuration: configuration)
}

@IBAction func objectRequest(_ sender: Any) {
Expand All @@ -33,8 +43,29 @@ class ViewController: UIViewController {
case .failure(let error):
debugPrint("🌹", error.localizedDescription)
}
})
}
}).response { (response: DefaultDataResponse) in
let jsonString = String(data: response.data!, encoding: .utf8)
print("🌹-- \(jsonString!) ---🌹")

}.responseData { (response: DataResponse<Data>) in
print("🌹-- \(response.result.value?.description) ---🌹")
}
// Alamofire.request(
// form.url,
// method: HTTPMethod.get,
// parameters: form.parameters(),
// encoding: form.encoding(),
// headers: form.headers()
// )
// .responseObject(keyPath: "data",completionHandler: { (response: DataResponse<Weather>) in
// switch response.result {
// case .success(let object):
// debugPrint("🌹", object.location)
// case .failure(let error):
// debugPrint("🌹", error.localizedDescription)
// }
// })
}

@IBAction func arrayRequest(_ sender: Any) {
let form = WeatherForm<Forecast>()
Expand All @@ -59,10 +90,10 @@ class ViewController: UIViewController {
}

@IBAction func nestedRequest(_ sender: Any) {
let form = WeatherForm<RootModel>()
requestFrom(form) { (response) in
debugPrint("🌹-- 来了", response)
}
// let form = WeatherForm<RootModel>()
// requestFrom(form) { (response) in
// debugPrint("🌹-- 来了", response)
// }
// Alamofire.request(
// form.url,
// method: HTTPMethod.get,
Expand All @@ -80,23 +111,41 @@ class ViewController: UIViewController {
// })
}

func requestFrom<T: Codable>(_ form: WeatherForm<T>, success: @escaping (_ result: T) -> Void ) {
Alamofire.request(
form.url,
method: HTTPMethod.get,
parameters: form.parameters(),
encoding: form.encoding(),
headers: form.headers()
).responseObject(completionHandler: { (response: DataResponse<T>) in
switch response.result {
case .success(let root):
// debugPrint("🌹", root)
success(root)
case .failure(let error):
debugPrint("🌹", error.localizedDescription)
}
})
}
// func requestFrom<T: Codable>(_ form: WeatherForm<T>, success: @escaping (_ result: T) -> Void ) {
// Alamofire.request(
// form.url,
// method: HTTPMethod.get,
// parameters: form.parameters(),
// encoding: form.encoding(),
// headers: form.headers()
// )
// .responseObject(completionHandler: { (response: DataResponse<T>) in
// switch response.result {
// case .success(let root):
//// debugPrint("🌹", root)
// success(root)
// case .failure(let error):
// debugPrint("🌹", error.localizedDescription)
// }
// })
// }

// func request<T: Codable>(
// _ form: WeatherForm<T>,
// success: ((T) -> Void)? = nil ,
// failure: ((_ error: Error) -> Void)? = nil
// ) {
// Alamofire.request(
// form.url,
// method: form.method,
// parameters: form.parameters(),
// encoding: form.encoding(),
// headers: form.headers()
// )
// .responseObject { (response: DataResponse<T>) in
//
// }
// }

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
Expand Down Expand Up @@ -148,6 +197,9 @@ struct WeatherForm<T: Codable> {
public func headers() -> [String: String] {
return ["accessToken": "xxx"]
}

}




Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit 4f87dab

Please sign in to comment.