├── .gitignore ├── LICENSE ├── README.md ├── RapidFire ├── Info.plist ├── RapidFire.Control.swift ├── RapidFire.MultipartFormData.swift ├── RapidFire.Request.swift ├── RapidFire.Response.swift ├── RapidFire.Setting.swift ├── RapidFire.Util.swift ├── RapidFire.h └── RapidFire.swift ├── RapidFireSample.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist └── xcshareddata │ └── xcschemes │ ├── RapidFire.xcscheme │ ├── RapidFireSample.xcscheme │ └── RapidFireTests.xcscheme ├── RapidFireSample ├── AppDelegate.swift ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── Info.plist └── ViewController.swift └── RapidFireTests ├── Info.plist ├── RequestTests.swift ├── SettingTests.swift ├── UtilTests.swift └── images └── circle.png /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by https://www.gitignore.io 2 | 3 | ### Swift ### 4 | # Xcode 5 | # 6 | build/ 7 | *.pbxuser 8 | !default.pbxuser 9 | *.mode1v3 10 | !default.mode1v3 11 | *.mode2v3 12 | !default.mode2v3 13 | *.perspectivev3 14 | !default.perspectivev3 15 | xcuserdata 16 | *.xccheckout 17 | *.moved-aside 18 | DerivedData 19 | *.hmap 20 | *.ipa 21 | *.xcuserstate 22 | 23 | # CocoaPods 24 | # 25 | # We recommend against adding the Pods directory to your .gitignore. However 26 | # you should judge for yourself, the pros and cons are mentioned at: 27 | # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control 28 | # 29 | Pods/ 30 | 31 | # Carthage 32 | # 33 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 34 | # 35 | Carthage/ 36 | 37 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2017 Yukihiko Kagiyama 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # RapidFire 2 | 3 | RapidFire is a simple networking library. It is suitable for casual use such as prototyping and example project. 4 | It wraps URLSession and is written in Swift. 5 | 6 | ## Requirements 7 | - Swift 5 8 | - iOS 8.0 or later 9 | 10 | ## Features 11 | - Chainable Request 12 | - GET / POST / PUT / PATCH / DELETE 13 | - URL / JSON Parameter Encoding 14 | - multipart/form-data 15 | - JSON to Array / JSON to Dictionary Helper Method 16 | 17 | 18 | ## Installation 19 | 20 | ### Carthage 21 | 22 | ```Cartfile 23 | github "keygx/RapidFire" 24 | ``` 25 | 26 | ### Swift versions support 27 | 28 | - Swift 5, tag "swift5" 29 | - Swift 4.2, tag "swift4.2" 30 | - Swift 4.1, tag "swift4.1" 31 | - Swift 4.0, tag "swift4.0" 32 | 33 | 34 | ## Usage 35 | 36 | ### Basic Request 37 | ```swift 38 | RapidFire(.get, "https://example.com/users") 39 | .setCompletionHandler({ (response: RapidFire.Response) in 40 | switch response.result { 41 | case .success: 42 | // success 43 | case .failure: 44 | // failure 45 | } 46 | }) 47 | .fire() 48 | ``` 49 | 50 | ### Init 51 | ```swift 52 | RapidFire(HTTP Method, baseURL) 53 | ``` 54 | 55 | ```swift 56 | // HTTP Method 57 | public enum HTTPMethod: String { 58 | case get = "GET" 59 | case post = "POST" 60 | case put = "PUT" 61 | case patch = "PATCH" 62 | case delete = "DELETE" 63 | } 64 | ``` 65 | ```swift 66 | // baseURL 67 | ex: "https://example.com" 68 | ``` 69 | 70 | ### Path 71 | ```swift 72 | .setPath("/path") 73 | ``` 74 | 75 | ### Headers 76 | ```swift 77 | .setHeaders(["x-myheader-1":"value1", "x-myheader-2":"value2"]) 78 | ``` 79 | 80 | ### Query Parameters 81 | ```swift 82 | .setQuery(["a":"1", "b":"2"]) //?a=1&b=2 83 | ``` 84 | 85 | ### Body Parameters 86 | ```swift 87 | .setBody(["a":"1", "b":"2"]) 88 | ``` 89 | 90 | ### application/json 91 | ```swift 92 | .setJSON(["a":"1", "b":"2"]) 93 | ``` 94 | 95 | ### multipart/form-data 96 | ```swift 97 | .setPartData(["a":"1", "b":"2"]) 98 | .setPartData(RapidFire.PartData(name: "image", filename: "sample.png", value: imageData, mimeType: "image/png")) 99 | ``` 100 | 101 | ### Timeout 102 | ```swift 103 | .setTimeout(30) //sec. 104 | ``` 105 | 106 | ### Retry 107 | ```swift 108 | .setRetry(3) //default interval 15 sec. 109 | 110 | .setRetry(3, intervalSec: 30) 111 | ``` 112 | 113 | ### Response 114 | ```swift 115 | .setCompletionHandler({ (response: RapidFire.Response) in 116 | switch response.result { 117 | case .success: 118 | print("success:\n \(response.statusCode as Any): \(response.response as Any)") 119 | print(response.toDictionary()) 120 | case .failure: 121 | print("error:\n \(response.statusCode as Any): \(response.error as Any)") 122 | } 123 | }) 124 | ``` 125 | 126 | ###### RapidFire.Response.swift 127 | ```swift 128 | public enum Result { 129 | case success 130 | case failure 131 | } 132 | 133 | public var result: Result 134 | public var statusCode: Int? 135 | public var data: Data? 136 | public var response: URLResponse? 137 | public var error: Error? 138 | 139 | 140 | // Convert JSON to Dictionary 141 | public func toDictionary() -> [String: Any] 142 | 143 | // Convert JSON to Array 144 | public func toArray() -> [[String: Any]] 145 | 146 | // Convert JSON to String 147 | public func toString() -> String 148 | ``` 149 | 150 | ### Utilities 151 | ```swift 152 | // Convert JSON to Dictionary 153 | RapidFire.Util.toDictionary(from: response.data) 154 | 155 | // Convert JSON to Array 156 | RapidFire.Util.toArray(from: response.data) 157 | 158 | // Convert JSON to String 159 | RapidFire.Util.toString(from: response.data) 160 | 161 | // Convert to JSON 162 | RapidFire.Util.toJson(from: ["a":"1", "b":"2"]) 163 | ``` 164 | 165 | 166 | ## License 167 | 168 | RapidFire is released under the MIT license. See LICENSE for details. 169 | 170 | ## Author 171 | 172 | Yukihiko Kagiyama (keygx) 173 | -------------------------------------------------------------------------------- /RapidFire/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.4.0 19 | CFBundleVersion 20 | 1.4.0 21 | NSPrincipalClass 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /RapidFire/RapidFire.Control.swift: -------------------------------------------------------------------------------- 1 | // 2 | // RapidFire.Control.swift 3 | // RapidFire 4 | // 5 | // Created by keygx on 2016/11/19. 6 | // Copyright © 2016年 keygx. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | extension RapidFire { 12 | 13 | // Session Start 14 | func start() { 15 | 16 | guard let method = settings.method, let baseUrl = settings.baseUrl else { 17 | // Item shortage 18 | return 19 | } 20 | 21 | guard let request = createURLRequest(method, baseUrl) else { 22 | // URLRequest creation failure 23 | return 24 | } 25 | 26 | // CompletionHandler 27 | let completionHandler: ((Data?, URLResponse?, Error?) -> Void) = { (data, response, error) in 28 | 29 | let statusCode = (response as? HTTPURLResponse)?.statusCode 30 | 31 | if error != nil { 32 | self.failure(statusCode, data, response, error) 33 | } else { 34 | self.success(statusCode, data, response, error) 35 | } 36 | } 37 | 38 | // URLSessionConfig 39 | let config = URLSessionConfiguration.default 40 | // URLSession 41 | let session = URLSession(configuration: config) 42 | 43 | // URLSessionDataTask 44 | task = session.dataTask(with: request as URLRequest, completionHandler: completionHandler) 45 | 46 | resume() 47 | } 48 | 49 | // Task Resume 50 | public func resume() { 51 | if let task = task { 52 | task.resume() 53 | } 54 | } 55 | 56 | // Task Suspend 57 | public func suspend() { 58 | if let task = task { 59 | task.suspend() 60 | } 61 | } 62 | 63 | // Task Cancel 64 | public func cancel() { 65 | if let task = task { 66 | task.cancel() 67 | } 68 | } 69 | } 70 | 71 | extension RapidFire { 72 | 73 | func failure(_ statusCode: Int?, _ data: Data?, _ response: URLResponse?, _ error: Error?) { 74 | if settings.retryCount > 0 { 75 | print("\(settings.retryCount) time remaining") 76 | settings.retryCount -= 1 77 | 78 | let dispatchTime: DispatchTime = DispatchTime.now() + DispatchTimeInterval.seconds(settings.retryInterval) 79 | DispatchQueue.global().asyncAfter(deadline: dispatchTime) { 80 | self.start() 81 | } 82 | } else { 83 | callback(RapidFire.Response(result: .failure, statusCode: statusCode, data: data, response: response, error: error)) 84 | } 85 | } 86 | 87 | func success(_ statusCode: Int?, _ data: Data?, _ response: URLResponse?, _ error: Error?) { 88 | callback(RapidFire.Response(result: .success, statusCode: statusCode, data: data, response: response, error: error)) 89 | } 90 | 91 | func callback(_ response: RapidFire.Response) { 92 | guard let handler = settings.completionHandler else { 93 | return 94 | } 95 | 96 | handler(response) 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /RapidFire/RapidFire.MultipartFormData.swift: -------------------------------------------------------------------------------- 1 | // 2 | // RapidFire.MultipartFormData.swift 3 | // RapidFire 4 | // 5 | // Created by keygx on 2016/11/19. 6 | // Copyright © 2016年 keygx. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | extension RapidFire { 12 | 13 | func boundary() -> String { 14 | #if TEST 15 | return "RapidFire-boundary-TEST" 16 | #else 17 | return String(format: "RapidFire-boundary-%08x-%08x", arc4random(), arc4random()) 18 | #endif 19 | } 20 | 21 | func buildMultipartFormData(request: URLRequest, params: [String: String]?, partData: [PartData]?) -> Data { 22 | 23 | let boundaryString = boundary() 24 | var body = Data() 25 | var formData = "" 26 | var request = request 27 | 28 | request.setValue("multipart/form-data; charset=utf-8; boundary=\(boundaryString)", forHTTPHeaderField: "Content-Type") 29 | 30 | // Params 31 | if let params = params { 32 | for (key, value) in params { 33 | formData = "\r\n" 34 | formData += "--\(boundaryString)" 35 | formData += "\r\n" 36 | formData += "Content-Disposition: form-data; name=\"\(key)\"" 37 | formData += "\r\n\r\n" 38 | formData += "\(value)" 39 | formData += "\r\n" 40 | body.append(formData.data(using: String.Encoding.utf8)!) 41 | } 42 | } 43 | 44 | // Data 45 | if let partData = partData { 46 | for data in partData { 47 | formData = "\r\n" 48 | formData += "--\(boundaryString)" 49 | formData += "\r\n" 50 | formData += "Content-Disposition: form-data; name=\"\(data.name)\"; filename=\"\(data.filename)\"" 51 | formData += "\r\n" 52 | formData += "Content-Type: \(data.mimeType)" 53 | formData += "\r\n\r\n" 54 | body.append(formData.data(using: String.Encoding.utf8)!) 55 | body.append(data.value) 56 | formData = "\r\n" 57 | body.append(formData.data(using: String.Encoding.utf8)!) 58 | } 59 | } 60 | 61 | // End boundary 62 | formData = "--\(boundaryString)" 63 | formData += "--\r\n\r\n" 64 | body.append(formData.data(using: String.Encoding.utf8)!) 65 | 66 | // Content-Length 67 | request.setValue(String(describing: body.count), forHTTPHeaderField: "Content-Length") 68 | 69 | return body 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /RapidFire/RapidFire.Request.swift: -------------------------------------------------------------------------------- 1 | // 2 | // RapidFire.Request.swift 3 | // RapidFire 4 | // 5 | // Created by keygx on 2016/11/19. 6 | // Copyright © 2016年 keygx. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | extension RapidFire { 12 | 13 | // Create URLRequest 14 | func createURLRequest(_ method: HTTPMethod, _ baseUrl: String) -> URLRequest? { 15 | 16 | var request: URLRequest? 17 | 18 | switch method { 19 | case .get: 20 | request = requestWithQuery(baseUrl) 21 | case .post, .put, .patch: 22 | request = requestWithBody(baseUrl) 23 | case .delete: 24 | if settings.query != nil { 25 | request = requestWithQuery(baseUrl) 26 | } else { 27 | request = requestWithBody(baseUrl) 28 | } 29 | } 30 | 31 | guard var validRequest = request else { return nil } 32 | 33 | // Method 34 | validRequest.httpMethod = method.rawValue 35 | 36 | // Timeout 37 | if let timeout = settings.timeoutInterval { 38 | validRequest.timeoutInterval = timeout 39 | } 40 | 41 | // Headers 42 | validRequest = addHeaders(request: validRequest) 43 | 44 | return validRequest 45 | } 46 | 47 | // QueryString 48 | func requestWithQuery(_ baseUrl: String) -> URLRequest? { 49 | // endpoint = baseUrl + path 50 | var endpoint = baseUrl + (settings.path ?? "") 51 | 52 | // Add query 53 | if let queryString = buildQueryParameters(parameters: settings.query) { 54 | endpoint = endpoint + "?" + queryString 55 | } 56 | 57 | guard let url = URL(string: endpoint) else { 58 | // URL creation failure 59 | return nil 60 | } 61 | 62 | // URLRequest 63 | let request = URLRequest(url: url) 64 | 65 | return request 66 | } 67 | 68 | // BodyMessage 69 | func requestWithBody(_ baseUrl: String) -> URLRequest? { 70 | // endpoint = baseUrl + path 71 | let endpoint = baseUrl + (settings.path ?? "") 72 | 73 | guard let url = URL(string: endpoint) else { 74 | // URL creation failure 75 | return nil 76 | } 77 | 78 | // URLRequest 79 | var request = URLRequest(url: url) 80 | 81 | // multipart-formdata 82 | if settings.partDataParams != nil || settings.partDataBinary != nil { 83 | let body = buildMultipartFormData(request: request, params: settings.partDataParams, partData: settings.partDataBinary) 84 | request.httpBody = body as Data 85 | 86 | return request 87 | } 88 | 89 | // add Body 90 | if let json = settings.json { 91 | // add Content-Type application/json 92 | request.setValue("application/json; charset=utf-8", forHTTPHeaderField: "Content-Type") 93 | do { 94 | // JSON 95 | request.httpBody = try JSONSerialization.data(withJSONObject: json, options: .prettyPrinted) 96 | return request 97 | } catch { 98 | return nil 99 | } 100 | } else if let data = settings.bodyData { 101 | // Data 102 | request.httpBody = data 103 | } else if let paramString = buildBodyParameters(parameters: settings.bodyParams) { 104 | // Parameters 105 | request.httpBody = paramString.data(using: String.Encoding.utf8) 106 | } 107 | 108 | return request 109 | } 110 | 111 | // Add Headers 112 | func addHeaders(request: URLRequest) -> URLRequest { 113 | 114 | guard let headers = settings.headers else { 115 | return request 116 | } 117 | 118 | var request = request 119 | 120 | for (key, value) in headers { 121 | request.setValue(value, forHTTPHeaderField: key) 122 | } 123 | 124 | return request 125 | } 126 | 127 | // Build Query Parameters 128 | func buildQueryParameters(parameters: [String: String]?) -> String? { 129 | 130 | guard let params = parameters else { 131 | return nil 132 | } 133 | 134 | var queries: [String] = [] 135 | 136 | for (key, value) in params { 137 | if let encoded = value.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlQueryAllowed) { 138 | queries.append(key + "=" + encoded) 139 | } 140 | } 141 | 142 | return queries.joined(separator: "&") 143 | } 144 | 145 | // Build Body Parameters 146 | func buildBodyParameters(parameters: [String: String]?) -> String? { 147 | 148 | guard let params = parameters else { 149 | return nil 150 | } 151 | 152 | var queries: [String] = [] 153 | 154 | for (key, value) in params { 155 | queries.append(key + "=" + value) 156 | } 157 | 158 | return queries.joined(separator: "&") 159 | } 160 | } 161 | -------------------------------------------------------------------------------- /RapidFire/RapidFire.Response.swift: -------------------------------------------------------------------------------- 1 | // 2 | // RapidFire.Response.swift 3 | // RapidFire 4 | // 5 | // Created by keygx on 2016/11/19. 6 | // Copyright © 2016年 keygx. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | extension RapidFire { 12 | 13 | // Response Data 14 | public struct Response { 15 | 16 | public enum Result { 17 | case success 18 | case failure 19 | } 20 | 21 | public var result: Result 22 | public var statusCode: Int? 23 | public var data: Data? 24 | public var response: URLResponse? 25 | public var error: Error? 26 | 27 | public init(result: Result, statusCode: Int?, data: Data?, response: URLResponse?, error: Error?) { 28 | self.result = result 29 | self.statusCode = statusCode 30 | self.data = data 31 | self.response = response 32 | self.error = error 33 | } 34 | } 35 | } 36 | 37 | extension RapidFire.Response { 38 | 39 | // Convert JSON to Dictionary 40 | public func toDictionary() -> [String: Any] { 41 | var dic = [String: Any]() 42 | 43 | if let jsonData = self.data { 44 | do { 45 | dic = try JSONSerialization.jsonObject(with: jsonData, options: .allowFragments) as! [String: Any] 46 | } catch { 47 | print("Converting Failed.") 48 | } 49 | } 50 | 51 | return dic 52 | } 53 | 54 | // Convert JSON to Array 55 | public func toArray() -> [[String: Any]] { 56 | var arr = [[String: Any]]() 57 | 58 | if let jsonData = self.data { 59 | do { 60 | arr = try JSONSerialization.jsonObject(with: jsonData, options: .allowFragments) as! [[String: Any]] 61 | } catch { 62 | print("Converting Failed.") 63 | } 64 | } 65 | 66 | return arr 67 | } 68 | 69 | // Convert JSON to String 70 | public func toString() -> String { 71 | if let stringData = self.data { 72 | if let string = String(data: stringData, encoding: String.Encoding.utf8) { 73 | return string 74 | } 75 | } 76 | 77 | return "" 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /RapidFire/RapidFire.Setting.swift: -------------------------------------------------------------------------------- 1 | // 2 | // RapidFire.Setting.swift 3 | // RapidFire 4 | // 5 | // Created by keygx on 2016/11/19. 6 | // Copyright © 2016年 keygx. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | extension RapidFire { 12 | 13 | public enum HTTPMethod: String { 14 | case get = "GET" 15 | case post = "POST" 16 | case put = "PUT" 17 | case patch = "PATCH" 18 | case delete = "DELETE" 19 | } 20 | 21 | public struct PartData { 22 | public var name: String 23 | public var filename: String 24 | public var value: Data 25 | public var mimeType: String 26 | 27 | public init(name: String, filename: String, value: Data, mimeType: String) { 28 | self.name = name 29 | self.filename = filename 30 | self.value = value 31 | self.mimeType = mimeType 32 | } 33 | } 34 | 35 | class RequestSetting { 36 | var method: HTTPMethod? 37 | var baseUrl: String? 38 | var path: String? 39 | var headers: [String: String]? 40 | var query: [String: String]? 41 | var bodyParams: [String: String]? 42 | var bodyData: Data? 43 | var json: [String: Any]? 44 | var partDataParams: [String: String]? 45 | var partDataBinary: [PartData]? 46 | var timeoutInterval: TimeInterval? 47 | var retryCount: Int = 0 48 | var retryInterval: Int = 15 49 | var completionHandler: ((RapidFire.Response) -> Void)? 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /RapidFire/RapidFire.Util.swift: -------------------------------------------------------------------------------- 1 | // 2 | // RapidFire.Util.swift 3 | // RapidFire 4 | // 5 | // Created by keygx on 2016/11/19. 6 | // Copyright © 2016年 keygx. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | extension RapidFire { 12 | 13 | public class Util { 14 | 15 | // Convert JSON to Dictionary 16 | public static func toDictionary(from data: Data?) -> [String: Any] { 17 | var dic = [String: Any]() 18 | 19 | if let jsonData = data { 20 | do { 21 | dic = try JSONSerialization.jsonObject(with: jsonData, options: .allowFragments) as! [String: Any] 22 | } catch { 23 | print("Converting Failed.") 24 | } 25 | } 26 | 27 | return dic 28 | } 29 | 30 | // Convert JSON to Array 31 | public static func toArray(from data: Data?) -> [[String: Any]] { 32 | var arr = [[String: Any]]() 33 | 34 | if let jsonData = data { 35 | do { 36 | arr = try JSONSerialization.jsonObject(with: jsonData, options: .allowFragments) as! [[String: Any]] 37 | } catch { 38 | print("Converting Failed.") 39 | } 40 | } 41 | 42 | return arr 43 | } 44 | 45 | // Convert JSON to String 46 | public static func toString(from data: Data?) -> String { 47 | if let stringData = data { 48 | if let string = String(data: stringData, encoding: String.Encoding.utf8) { 49 | return string 50 | } 51 | } 52 | 53 | return "" 54 | } 55 | 56 | // Convert to JSON 57 | public static func toJSON(from object: Any) -> Data { 58 | var json = Data() 59 | 60 | do { 61 | json = try JSONSerialization.data(withJSONObject: object, options: .prettyPrinted) 62 | } catch { 63 | print("JSON Generation failed.") 64 | } 65 | 66 | return json 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /RapidFire/RapidFire.h: -------------------------------------------------------------------------------- 1 | // 2 | // RapidFire.h 3 | // RapidFire 4 | // 5 | // Created by keygx on 2016/11/19. 6 | // Copyright © 2016年 keygx. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | //! Project version number for RapidFire. 12 | FOUNDATION_EXPORT double RapidFireVersionNumber; 13 | 14 | //! Project version string for RapidFire. 15 | FOUNDATION_EXPORT const unsigned char RapidFireVersionString[]; 16 | 17 | // In this header, you should import all the public headers of your framework using statements like #import 18 | 19 | 20 | -------------------------------------------------------------------------------- /RapidFire/RapidFire.swift: -------------------------------------------------------------------------------- 1 | // 2 | // RapidFire.swift 3 | // RapidFire 4 | // 5 | // Created by keygx on 2016/11/19. 6 | // Copyright © 2016年 keygx. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | public class RapidFire { 12 | 13 | var settings = RapidFire.RequestSetting() 14 | var task: URLSessionDataTask? 15 | 16 | public init() {} 17 | 18 | public init(_ method: HTTPMethod, _ baseUrl: String) { 19 | settings.method = method 20 | settings.baseUrl = baseUrl 21 | } 22 | 23 | public func setPath(_ path: String) -> Self { 24 | settings.path = path 25 | return self 26 | } 27 | 28 | public func setHeaders(_ headers: [String: String]) -> Self { 29 | settings.headers = headers 30 | return self 31 | } 32 | 33 | public func setQuery(_ params: [String: String]) -> Self { 34 | settings.query = params 35 | return self 36 | } 37 | 38 | public func setBody(_ params: [String: String]) -> Self { 39 | settings.bodyParams = params 40 | return self 41 | } 42 | 43 | public func setBody(_ params: Data) -> Self { 44 | settings.bodyData = params 45 | return self 46 | } 47 | 48 | public func setJSON(_ json: [String: Any]) -> Self { 49 | settings.json = json 50 | return self 51 | } 52 | 53 | public func setPartData(_ params: [String: String]) -> Self { 54 | settings.partDataParams = params 55 | return self 56 | } 57 | 58 | public func setPartData(_ data: PartData) -> Self { 59 | if settings.partDataBinary == nil { 60 | settings.partDataBinary = [PartData]() 61 | } 62 | settings.partDataBinary?.append(data) 63 | return self 64 | } 65 | 66 | public func setTimeout(_ timeout: TimeInterval) -> Self { 67 | settings.timeoutInterval = timeout 68 | return self 69 | } 70 | 71 | public func setRetry(_ count: Int, intervalSec: Int = 10) -> Self { 72 | settings.retryCount = count 73 | settings.retryInterval = intervalSec 74 | return self 75 | } 76 | 77 | public func setCompletionHandler(_ handler: @escaping (RapidFire.Response) -> Void) -> Self { 78 | settings.completionHandler = handler 79 | return self 80 | } 81 | 82 | public func fire() { 83 | DispatchQueue.global().async { 84 | self.start() 85 | } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /RapidFireSample.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 36062A221DE80C0F00804AA0 /* RequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36062A211DE80C0F00804AA0 /* RequestTests.swift */; }; 11 | 3690DEA51DE82A0800C45A96 /* SettingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3690DEA41DE82A0800C45A96 /* SettingTests.swift */; }; 12 | 3690DEA71DE83AAC00C45A96 /* circle.png in Resources */ = {isa = PBXBuildFile; fileRef = 3690DEA61DE83AAC00C45A96 /* circle.png */; }; 13 | 36A447DD1DE02BAA00DC48CE /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36A447DC1DE02BAA00DC48CE /* AppDelegate.swift */; }; 14 | 36A447DF1DE02BAA00DC48CE /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36A447DE1DE02BAA00DC48CE /* ViewController.swift */; }; 15 | 36A447E21DE02BAA00DC48CE /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 36A447E01DE02BAA00DC48CE /* Main.storyboard */; }; 16 | 36A447E41DE02BAA00DC48CE /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 36A447E31DE02BAA00DC48CE /* Assets.xcassets */; }; 17 | 36A447E71DE02BAA00DC48CE /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 36A447E51DE02BAA00DC48CE /* LaunchScreen.storyboard */; }; 18 | 36A447FC1DE02BF800DC48CE /* RapidFire.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 36A447F31DE02BF700DC48CE /* RapidFire.framework */; }; 19 | 36A448031DE02BF800DC48CE /* UtilTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36A448021DE02BF800DC48CE /* UtilTests.swift */; }; 20 | 36A448051DE02BF800DC48CE /* RapidFire.h in Headers */ = {isa = PBXBuildFile; fileRef = 36A447F51DE02BF700DC48CE /* RapidFire.h */; settings = {ATTRIBUTES = (Public, ); }; }; 21 | 36A448081DE02BF800DC48CE /* RapidFire.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 36A447F31DE02BF700DC48CE /* RapidFire.framework */; }; 22 | 36A448091DE02BF800DC48CE /* RapidFire.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 36A447F31DE02BF700DC48CE /* RapidFire.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 23 | 36A448171DE0306D00DC48CE /* RapidFire.Control.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36A448111DE0306D00DC48CE /* RapidFire.Control.swift */; }; 24 | 36A448181DE0306D00DC48CE /* RapidFire.Request.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36A448121DE0306D00DC48CE /* RapidFire.Request.swift */; }; 25 | 36A448191DE0306D00DC48CE /* RapidFire.Response.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36A448131DE0306D00DC48CE /* RapidFire.Response.swift */; }; 26 | 36A4481A1DE0306D00DC48CE /* RapidFire.Setting.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36A448141DE0306D00DC48CE /* RapidFire.Setting.swift */; }; 27 | 36A4481B1DE0306D00DC48CE /* RapidFire.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36A448151DE0306D00DC48CE /* RapidFire.swift */; }; 28 | 36A4481C1DE0306D00DC48CE /* RapidFire.Util.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36A448161DE0306D00DC48CE /* RapidFire.Util.swift */; }; 29 | 36A448201DE093A500DC48CE /* RapidFire.MultipartFormData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36A4481F1DE093A500DC48CE /* RapidFire.MultipartFormData.swift */; }; 30 | /* End PBXBuildFile section */ 31 | 32 | /* Begin PBXContainerItemProxy section */ 33 | 36A447FD1DE02BF800DC48CE /* PBXContainerItemProxy */ = { 34 | isa = PBXContainerItemProxy; 35 | containerPortal = 36A447D11DE02BAA00DC48CE /* Project object */; 36 | proxyType = 1; 37 | remoteGlobalIDString = 36A447F21DE02BF700DC48CE; 38 | remoteInfo = RapidFire; 39 | }; 40 | 36A448061DE02BF800DC48CE /* PBXContainerItemProxy */ = { 41 | isa = PBXContainerItemProxy; 42 | containerPortal = 36A447D11DE02BAA00DC48CE /* Project object */; 43 | proxyType = 1; 44 | remoteGlobalIDString = 36A447F21DE02BF700DC48CE; 45 | remoteInfo = RapidFire; 46 | }; 47 | /* End PBXContainerItemProxy section */ 48 | 49 | /* Begin PBXCopyFilesBuildPhase section */ 50 | 36A4480D1DE02BF800DC48CE /* Embed Frameworks */ = { 51 | isa = PBXCopyFilesBuildPhase; 52 | buildActionMask = 2147483647; 53 | dstPath = ""; 54 | dstSubfolderSpec = 10; 55 | files = ( 56 | 36A448091DE02BF800DC48CE /* RapidFire.framework in Embed Frameworks */, 57 | ); 58 | name = "Embed Frameworks"; 59 | runOnlyForDeploymentPostprocessing = 0; 60 | }; 61 | /* End PBXCopyFilesBuildPhase section */ 62 | 63 | /* Begin PBXFileReference section */ 64 | 36062A211DE80C0F00804AA0 /* RequestTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RequestTests.swift; sourceTree = ""; }; 65 | 3690DEA41DE82A0800C45A96 /* SettingTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SettingTests.swift; sourceTree = ""; }; 66 | 3690DEA61DE83AAC00C45A96 /* circle.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = circle.png; path = images/circle.png; sourceTree = ""; }; 67 | 36A447D91DE02BAA00DC48CE /* RapidFireSample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = RapidFireSample.app; sourceTree = BUILT_PRODUCTS_DIR; }; 68 | 36A447DC1DE02BAA00DC48CE /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 69 | 36A447DE1DE02BAA00DC48CE /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 70 | 36A447E11DE02BAA00DC48CE /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 71 | 36A447E31DE02BAA00DC48CE /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 72 | 36A447E61DE02BAA00DC48CE /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 73 | 36A447E81DE02BAA00DC48CE /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 74 | 36A447F31DE02BF700DC48CE /* RapidFire.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = RapidFire.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 75 | 36A447F51DE02BF700DC48CE /* RapidFire.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RapidFire.h; sourceTree = ""; }; 76 | 36A447F61DE02BF800DC48CE /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 77 | 36A447FB1DE02BF800DC48CE /* RapidFireTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = RapidFireTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 78 | 36A448021DE02BF800DC48CE /* UtilTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UtilTests.swift; sourceTree = ""; }; 79 | 36A448041DE02BF800DC48CE /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 80 | 36A448111DE0306D00DC48CE /* RapidFire.Control.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RapidFire.Control.swift; sourceTree = ""; }; 81 | 36A448121DE0306D00DC48CE /* RapidFire.Request.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RapidFire.Request.swift; sourceTree = ""; }; 82 | 36A448131DE0306D00DC48CE /* RapidFire.Response.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RapidFire.Response.swift; sourceTree = ""; }; 83 | 36A448141DE0306D00DC48CE /* RapidFire.Setting.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RapidFire.Setting.swift; sourceTree = ""; }; 84 | 36A448151DE0306D00DC48CE /* RapidFire.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RapidFire.swift; sourceTree = ""; }; 85 | 36A448161DE0306D00DC48CE /* RapidFire.Util.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RapidFire.Util.swift; sourceTree = ""; }; 86 | 36A4481F1DE093A500DC48CE /* RapidFire.MultipartFormData.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RapidFire.MultipartFormData.swift; sourceTree = ""; }; 87 | /* End PBXFileReference section */ 88 | 89 | /* Begin PBXFrameworksBuildPhase section */ 90 | 36A447D61DE02BAA00DC48CE /* Frameworks */ = { 91 | isa = PBXFrameworksBuildPhase; 92 | buildActionMask = 2147483647; 93 | files = ( 94 | 36A448081DE02BF800DC48CE /* RapidFire.framework in Frameworks */, 95 | ); 96 | runOnlyForDeploymentPostprocessing = 0; 97 | }; 98 | 36A447EF1DE02BF700DC48CE /* Frameworks */ = { 99 | isa = PBXFrameworksBuildPhase; 100 | buildActionMask = 2147483647; 101 | files = ( 102 | ); 103 | runOnlyForDeploymentPostprocessing = 0; 104 | }; 105 | 36A447F81DE02BF800DC48CE /* Frameworks */ = { 106 | isa = PBXFrameworksBuildPhase; 107 | buildActionMask = 2147483647; 108 | files = ( 109 | 36A447FC1DE02BF800DC48CE /* RapidFire.framework in Frameworks */, 110 | ); 111 | runOnlyForDeploymentPostprocessing = 0; 112 | }; 113 | /* End PBXFrameworksBuildPhase section */ 114 | 115 | /* Begin PBXGroup section */ 116 | 36A447D01DE02BAA00DC48CE = { 117 | isa = PBXGroup; 118 | children = ( 119 | 36A447DB1DE02BAA00DC48CE /* RapidFireSample */, 120 | 36A447F41DE02BF700DC48CE /* RapidFire */, 121 | 36A448011DE02BF800DC48CE /* RapidFireTests */, 122 | 36A447DA1DE02BAA00DC48CE /* Products */, 123 | ); 124 | sourceTree = ""; 125 | }; 126 | 36A447DA1DE02BAA00DC48CE /* Products */ = { 127 | isa = PBXGroup; 128 | children = ( 129 | 36A447D91DE02BAA00DC48CE /* RapidFireSample.app */, 130 | 36A447F31DE02BF700DC48CE /* RapidFire.framework */, 131 | 36A447FB1DE02BF800DC48CE /* RapidFireTests.xctest */, 132 | ); 133 | name = Products; 134 | sourceTree = ""; 135 | }; 136 | 36A447DB1DE02BAA00DC48CE /* RapidFireSample */ = { 137 | isa = PBXGroup; 138 | children = ( 139 | 36A447DC1DE02BAA00DC48CE /* AppDelegate.swift */, 140 | 36A447DE1DE02BAA00DC48CE /* ViewController.swift */, 141 | 36A447E01DE02BAA00DC48CE /* Main.storyboard */, 142 | 36A447E31DE02BAA00DC48CE /* Assets.xcassets */, 143 | 36A447E51DE02BAA00DC48CE /* LaunchScreen.storyboard */, 144 | 36A447E81DE02BAA00DC48CE /* Info.plist */, 145 | ); 146 | path = RapidFireSample; 147 | sourceTree = ""; 148 | }; 149 | 36A447F41DE02BF700DC48CE /* RapidFire */ = { 150 | isa = PBXGroup; 151 | children = ( 152 | 36A448151DE0306D00DC48CE /* RapidFire.swift */, 153 | 36A448141DE0306D00DC48CE /* RapidFire.Setting.swift */, 154 | 36A448111DE0306D00DC48CE /* RapidFire.Control.swift */, 155 | 36A448121DE0306D00DC48CE /* RapidFire.Request.swift */, 156 | 36A4481F1DE093A500DC48CE /* RapidFire.MultipartFormData.swift */, 157 | 36A448131DE0306D00DC48CE /* RapidFire.Response.swift */, 158 | 36A448161DE0306D00DC48CE /* RapidFire.Util.swift */, 159 | 36A447F51DE02BF700DC48CE /* RapidFire.h */, 160 | 36A447F61DE02BF800DC48CE /* Info.plist */, 161 | ); 162 | path = RapidFire; 163 | sourceTree = ""; 164 | }; 165 | 36A448011DE02BF800DC48CE /* RapidFireTests */ = { 166 | isa = PBXGroup; 167 | children = ( 168 | 3690DEA61DE83AAC00C45A96 /* circle.png */, 169 | 3690DEA41DE82A0800C45A96 /* SettingTests.swift */, 170 | 36062A211DE80C0F00804AA0 /* RequestTests.swift */, 171 | 36A448021DE02BF800DC48CE /* UtilTests.swift */, 172 | 36A448041DE02BF800DC48CE /* Info.plist */, 173 | ); 174 | path = RapidFireTests; 175 | sourceTree = ""; 176 | }; 177 | /* End PBXGroup section */ 178 | 179 | /* Begin PBXHeadersBuildPhase section */ 180 | 36A447F01DE02BF700DC48CE /* Headers */ = { 181 | isa = PBXHeadersBuildPhase; 182 | buildActionMask = 2147483647; 183 | files = ( 184 | 36A448051DE02BF800DC48CE /* RapidFire.h in Headers */, 185 | ); 186 | runOnlyForDeploymentPostprocessing = 0; 187 | }; 188 | /* End PBXHeadersBuildPhase section */ 189 | 190 | /* Begin PBXNativeTarget section */ 191 | 36A447D81DE02BAA00DC48CE /* RapidFireSample */ = { 192 | isa = PBXNativeTarget; 193 | buildConfigurationList = 36A447EB1DE02BAA00DC48CE /* Build configuration list for PBXNativeTarget "RapidFireSample" */; 194 | buildPhases = ( 195 | 36A447D51DE02BAA00DC48CE /* Sources */, 196 | 36A447D61DE02BAA00DC48CE /* Frameworks */, 197 | 36A447D71DE02BAA00DC48CE /* Resources */, 198 | 36A4480D1DE02BF800DC48CE /* Embed Frameworks */, 199 | ); 200 | buildRules = ( 201 | ); 202 | dependencies = ( 203 | 36A448071DE02BF800DC48CE /* PBXTargetDependency */, 204 | ); 205 | name = RapidFireSample; 206 | productName = RapidFireSample; 207 | productReference = 36A447D91DE02BAA00DC48CE /* RapidFireSample.app */; 208 | productType = "com.apple.product-type.application"; 209 | }; 210 | 36A447F21DE02BF700DC48CE /* RapidFire */ = { 211 | isa = PBXNativeTarget; 212 | buildConfigurationList = 36A4480A1DE02BF800DC48CE /* Build configuration list for PBXNativeTarget "RapidFire" */; 213 | buildPhases = ( 214 | 36A447EE1DE02BF700DC48CE /* Sources */, 215 | 36A447EF1DE02BF700DC48CE /* Frameworks */, 216 | 36A447F01DE02BF700DC48CE /* Headers */, 217 | 36A447F11DE02BF700DC48CE /* Resources */, 218 | ); 219 | buildRules = ( 220 | ); 221 | dependencies = ( 222 | ); 223 | name = RapidFire; 224 | productName = RapidFire; 225 | productReference = 36A447F31DE02BF700DC48CE /* RapidFire.framework */; 226 | productType = "com.apple.product-type.framework"; 227 | }; 228 | 36A447FA1DE02BF800DC48CE /* RapidFireTests */ = { 229 | isa = PBXNativeTarget; 230 | buildConfigurationList = 36A4480E1DE02BF800DC48CE /* Build configuration list for PBXNativeTarget "RapidFireTests" */; 231 | buildPhases = ( 232 | 36A447F71DE02BF800DC48CE /* Sources */, 233 | 36A447F81DE02BF800DC48CE /* Frameworks */, 234 | 36A447F91DE02BF800DC48CE /* Resources */, 235 | ); 236 | buildRules = ( 237 | ); 238 | dependencies = ( 239 | 36A447FE1DE02BF800DC48CE /* PBXTargetDependency */, 240 | ); 241 | name = RapidFireTests; 242 | productName = RapidFireTests; 243 | productReference = 36A447FB1DE02BF800DC48CE /* RapidFireTests.xctest */; 244 | productType = "com.apple.product-type.bundle.unit-test"; 245 | }; 246 | /* End PBXNativeTarget section */ 247 | 248 | /* Begin PBXProject section */ 249 | 36A447D11DE02BAA00DC48CE /* Project object */ = { 250 | isa = PBXProject; 251 | attributes = { 252 | LastSwiftUpdateCheck = 0810; 253 | LastUpgradeCheck = 1020; 254 | ORGANIZATIONNAME = keygx; 255 | TargetAttributes = { 256 | 36A447D81DE02BAA00DC48CE = { 257 | CreatedOnToolsVersion = 8.1; 258 | DevelopmentTeam = 3CCNMX7TC9; 259 | LastSwiftMigration = 1020; 260 | ProvisioningStyle = Automatic; 261 | }; 262 | 36A447F21DE02BF700DC48CE = { 263 | CreatedOnToolsVersion = 8.1; 264 | DevelopmentTeam = 3CCNMX7TC9; 265 | LastSwiftMigration = 1020; 266 | ProvisioningStyle = Automatic; 267 | }; 268 | 36A447FA1DE02BF800DC48CE = { 269 | CreatedOnToolsVersion = 8.1; 270 | DevelopmentTeam = 3CCNMX7TC9; 271 | LastSwiftMigration = 0900; 272 | ProvisioningStyle = Automatic; 273 | TestTargetID = 36A447D81DE02BAA00DC48CE; 274 | }; 275 | }; 276 | }; 277 | buildConfigurationList = 36A447D41DE02BAA00DC48CE /* Build configuration list for PBXProject "RapidFireSample" */; 278 | compatibilityVersion = "Xcode 3.2"; 279 | developmentRegion = en; 280 | hasScannedForEncodings = 0; 281 | knownRegions = ( 282 | en, 283 | Base, 284 | ); 285 | mainGroup = 36A447D01DE02BAA00DC48CE; 286 | productRefGroup = 36A447DA1DE02BAA00DC48CE /* Products */; 287 | projectDirPath = ""; 288 | projectRoot = ""; 289 | targets = ( 290 | 36A447D81DE02BAA00DC48CE /* RapidFireSample */, 291 | 36A447F21DE02BF700DC48CE /* RapidFire */, 292 | 36A447FA1DE02BF800DC48CE /* RapidFireTests */, 293 | ); 294 | }; 295 | /* End PBXProject section */ 296 | 297 | /* Begin PBXResourcesBuildPhase section */ 298 | 36A447D71DE02BAA00DC48CE /* Resources */ = { 299 | isa = PBXResourcesBuildPhase; 300 | buildActionMask = 2147483647; 301 | files = ( 302 | 36A447E71DE02BAA00DC48CE /* LaunchScreen.storyboard in Resources */, 303 | 36A447E41DE02BAA00DC48CE /* Assets.xcassets in Resources */, 304 | 36A447E21DE02BAA00DC48CE /* Main.storyboard in Resources */, 305 | ); 306 | runOnlyForDeploymentPostprocessing = 0; 307 | }; 308 | 36A447F11DE02BF700DC48CE /* Resources */ = { 309 | isa = PBXResourcesBuildPhase; 310 | buildActionMask = 2147483647; 311 | files = ( 312 | ); 313 | runOnlyForDeploymentPostprocessing = 0; 314 | }; 315 | 36A447F91DE02BF800DC48CE /* Resources */ = { 316 | isa = PBXResourcesBuildPhase; 317 | buildActionMask = 2147483647; 318 | files = ( 319 | 3690DEA71DE83AAC00C45A96 /* circle.png in Resources */, 320 | ); 321 | runOnlyForDeploymentPostprocessing = 0; 322 | }; 323 | /* End PBXResourcesBuildPhase section */ 324 | 325 | /* Begin PBXSourcesBuildPhase section */ 326 | 36A447D51DE02BAA00DC48CE /* Sources */ = { 327 | isa = PBXSourcesBuildPhase; 328 | buildActionMask = 2147483647; 329 | files = ( 330 | 36A447DF1DE02BAA00DC48CE /* ViewController.swift in Sources */, 331 | 36A447DD1DE02BAA00DC48CE /* AppDelegate.swift in Sources */, 332 | ); 333 | runOnlyForDeploymentPostprocessing = 0; 334 | }; 335 | 36A447EE1DE02BF700DC48CE /* Sources */ = { 336 | isa = PBXSourcesBuildPhase; 337 | buildActionMask = 2147483647; 338 | files = ( 339 | 36A448201DE093A500DC48CE /* RapidFire.MultipartFormData.swift in Sources */, 340 | 36A4481A1DE0306D00DC48CE /* RapidFire.Setting.swift in Sources */, 341 | 36A448191DE0306D00DC48CE /* RapidFire.Response.swift in Sources */, 342 | 36A448171DE0306D00DC48CE /* RapidFire.Control.swift in Sources */, 343 | 36A4481B1DE0306D00DC48CE /* RapidFire.swift in Sources */, 344 | 36A448181DE0306D00DC48CE /* RapidFire.Request.swift in Sources */, 345 | 36A4481C1DE0306D00DC48CE /* RapidFire.Util.swift in Sources */, 346 | ); 347 | runOnlyForDeploymentPostprocessing = 0; 348 | }; 349 | 36A447F71DE02BF800DC48CE /* Sources */ = { 350 | isa = PBXSourcesBuildPhase; 351 | buildActionMask = 2147483647; 352 | files = ( 353 | 36A448031DE02BF800DC48CE /* UtilTests.swift in Sources */, 354 | 36062A221DE80C0F00804AA0 /* RequestTests.swift in Sources */, 355 | 3690DEA51DE82A0800C45A96 /* SettingTests.swift in Sources */, 356 | ); 357 | runOnlyForDeploymentPostprocessing = 0; 358 | }; 359 | /* End PBXSourcesBuildPhase section */ 360 | 361 | /* Begin PBXTargetDependency section */ 362 | 36A447FE1DE02BF800DC48CE /* PBXTargetDependency */ = { 363 | isa = PBXTargetDependency; 364 | target = 36A447F21DE02BF700DC48CE /* RapidFire */; 365 | targetProxy = 36A447FD1DE02BF800DC48CE /* PBXContainerItemProxy */; 366 | }; 367 | 36A448071DE02BF800DC48CE /* PBXTargetDependency */ = { 368 | isa = PBXTargetDependency; 369 | target = 36A447F21DE02BF700DC48CE /* RapidFire */; 370 | targetProxy = 36A448061DE02BF800DC48CE /* PBXContainerItemProxy */; 371 | }; 372 | /* End PBXTargetDependency section */ 373 | 374 | /* Begin PBXVariantGroup section */ 375 | 36A447E01DE02BAA00DC48CE /* Main.storyboard */ = { 376 | isa = PBXVariantGroup; 377 | children = ( 378 | 36A447E11DE02BAA00DC48CE /* Base */, 379 | ); 380 | name = Main.storyboard; 381 | sourceTree = ""; 382 | }; 383 | 36A447E51DE02BAA00DC48CE /* LaunchScreen.storyboard */ = { 384 | isa = PBXVariantGroup; 385 | children = ( 386 | 36A447E61DE02BAA00DC48CE /* Base */, 387 | ); 388 | name = LaunchScreen.storyboard; 389 | sourceTree = ""; 390 | }; 391 | /* End PBXVariantGroup section */ 392 | 393 | /* Begin XCBuildConfiguration section */ 394 | 3612F1381DF6839F00BAB9FB /* Test */ = { 395 | isa = XCBuildConfiguration; 396 | buildSettings = { 397 | ALWAYS_SEARCH_USER_PATHS = NO; 398 | CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; 399 | CLANG_ANALYZER_NONNULL = YES; 400 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 401 | CLANG_CXX_LIBRARY = "libc++"; 402 | CLANG_ENABLE_MODULES = YES; 403 | CLANG_ENABLE_OBJC_ARC = YES; 404 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 405 | CLANG_WARN_BOOL_CONVERSION = YES; 406 | CLANG_WARN_COMMA = YES; 407 | CLANG_WARN_CONSTANT_CONVERSION = YES; 408 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 409 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 410 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 411 | CLANG_WARN_EMPTY_BODY = YES; 412 | CLANG_WARN_ENUM_CONVERSION = YES; 413 | CLANG_WARN_INFINITE_RECURSION = YES; 414 | CLANG_WARN_INT_CONVERSION = YES; 415 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 416 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 417 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 418 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 419 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 420 | CLANG_WARN_STRICT_PROTOTYPES = YES; 421 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 422 | CLANG_WARN_SUSPICIOUS_MOVES = YES; 423 | CLANG_WARN_UNREACHABLE_CODE = YES; 424 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 425 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 426 | COPY_PHASE_STRIP = NO; 427 | DEBUG_INFORMATION_FORMAT = dwarf; 428 | ENABLE_STRICT_OBJC_MSGSEND = YES; 429 | ENABLE_TESTABILITY = YES; 430 | GCC_C_LANGUAGE_STANDARD = gnu99; 431 | GCC_DYNAMIC_NO_PIC = NO; 432 | GCC_NO_COMMON_BLOCKS = YES; 433 | GCC_OPTIMIZATION_LEVEL = 0; 434 | GCC_PREPROCESSOR_DEFINITIONS = ( 435 | "DEBUG=1", 436 | "$(inherited)", 437 | ); 438 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 439 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 440 | GCC_WARN_UNDECLARED_SELECTOR = YES; 441 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 442 | GCC_WARN_UNUSED_FUNCTION = YES; 443 | GCC_WARN_UNUSED_VARIABLE = YES; 444 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 445 | MTL_ENABLE_DEBUG_INFO = YES; 446 | ONLY_ACTIVE_ARCH = YES; 447 | SDKROOT = iphoneos; 448 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG TEST"; 449 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 450 | SWIFT_VERSION = ""; 451 | }; 452 | name = Test; 453 | }; 454 | 3612F1391DF6839F00BAB9FB /* Test */ = { 455 | isa = XCBuildConfiguration; 456 | buildSettings = { 457 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 458 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 459 | DEVELOPMENT_TEAM = 3CCNMX7TC9; 460 | INFOPLIST_FILE = RapidFireSample/Info.plist; 461 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 462 | OTHER_LDFLAGS = "-DTEST"; 463 | PRODUCT_BUNDLE_IDENTIFIER = com.keygraphix.ios.RapidFireSample; 464 | PRODUCT_NAME = "$(TARGET_NAME)"; 465 | SWIFT_VERSION = 5.0; 466 | }; 467 | name = Test; 468 | }; 469 | 3612F13A1DF6839F00BAB9FB /* Test */ = { 470 | isa = XCBuildConfiguration; 471 | buildSettings = { 472 | CLANG_ENABLE_MODULES = YES; 473 | CODE_SIGN_IDENTITY = ""; 474 | CURRENT_PROJECT_VERSION = 1; 475 | DEFINES_MODULE = YES; 476 | DEVELOPMENT_TEAM = 3CCNMX7TC9; 477 | DYLIB_COMPATIBILITY_VERSION = 1; 478 | DYLIB_CURRENT_VERSION = 1; 479 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 480 | INFOPLIST_FILE = RapidFire/Info.plist; 481 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 482 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 483 | OTHER_LDFLAGS = "-DTEST"; 484 | PRODUCT_BUNDLE_IDENTIFIER = com.keygraphix.ios.RapidFire; 485 | PRODUCT_NAME = "$(TARGET_NAME)"; 486 | SKIP_INSTALL = YES; 487 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 488 | SWIFT_VERSION = 5.0; 489 | TARGETED_DEVICE_FAMILY = "1,2"; 490 | VERSIONING_SYSTEM = "apple-generic"; 491 | VERSION_INFO_PREFIX = ""; 492 | }; 493 | name = Test; 494 | }; 495 | 3612F13B1DF6839F00BAB9FB /* Test */ = { 496 | isa = XCBuildConfiguration; 497 | buildSettings = { 498 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 499 | DEVELOPMENT_TEAM = 3CCNMX7TC9; 500 | INFOPLIST_FILE = RapidFireTests/Info.plist; 501 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 502 | OTHER_LDFLAGS = "-DTEST"; 503 | PRODUCT_BUNDLE_IDENTIFIER = com.keygraphix.ios.RapidFireTests; 504 | PRODUCT_NAME = "$(TARGET_NAME)"; 505 | SWIFT_SWIFT3_OBJC_INFERENCE = Default; 506 | SWIFT_VERSION = 5.0; 507 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/RapidFireSample.app/RapidFireSample"; 508 | }; 509 | name = Test; 510 | }; 511 | 36A447E91DE02BAA00DC48CE /* Debug */ = { 512 | isa = XCBuildConfiguration; 513 | buildSettings = { 514 | ALWAYS_SEARCH_USER_PATHS = NO; 515 | CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; 516 | CLANG_ANALYZER_NONNULL = YES; 517 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 518 | CLANG_CXX_LIBRARY = "libc++"; 519 | CLANG_ENABLE_MODULES = YES; 520 | CLANG_ENABLE_OBJC_ARC = YES; 521 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 522 | CLANG_WARN_BOOL_CONVERSION = YES; 523 | CLANG_WARN_COMMA = YES; 524 | CLANG_WARN_CONSTANT_CONVERSION = YES; 525 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 526 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 527 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 528 | CLANG_WARN_EMPTY_BODY = YES; 529 | CLANG_WARN_ENUM_CONVERSION = YES; 530 | CLANG_WARN_INFINITE_RECURSION = YES; 531 | CLANG_WARN_INT_CONVERSION = YES; 532 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 533 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 534 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 535 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 536 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 537 | CLANG_WARN_STRICT_PROTOTYPES = YES; 538 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 539 | CLANG_WARN_SUSPICIOUS_MOVES = YES; 540 | CLANG_WARN_UNREACHABLE_CODE = YES; 541 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 542 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 543 | COPY_PHASE_STRIP = NO; 544 | DEBUG_INFORMATION_FORMAT = dwarf; 545 | ENABLE_STRICT_OBJC_MSGSEND = YES; 546 | ENABLE_TESTABILITY = YES; 547 | GCC_C_LANGUAGE_STANDARD = gnu99; 548 | GCC_DYNAMIC_NO_PIC = NO; 549 | GCC_NO_COMMON_BLOCKS = YES; 550 | GCC_OPTIMIZATION_LEVEL = 0; 551 | GCC_PREPROCESSOR_DEFINITIONS = ( 552 | "DEBUG=1", 553 | "$(inherited)", 554 | ); 555 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 556 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 557 | GCC_WARN_UNDECLARED_SELECTOR = YES; 558 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 559 | GCC_WARN_UNUSED_FUNCTION = YES; 560 | GCC_WARN_UNUSED_VARIABLE = YES; 561 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 562 | MTL_ENABLE_DEBUG_INFO = YES; 563 | ONLY_ACTIVE_ARCH = YES; 564 | SDKROOT = iphoneos; 565 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 566 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 567 | SWIFT_VERSION = ""; 568 | }; 569 | name = Debug; 570 | }; 571 | 36A447EA1DE02BAA00DC48CE /* Release */ = { 572 | isa = XCBuildConfiguration; 573 | buildSettings = { 574 | ALWAYS_SEARCH_USER_PATHS = NO; 575 | CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; 576 | CLANG_ANALYZER_NONNULL = YES; 577 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 578 | CLANG_CXX_LIBRARY = "libc++"; 579 | CLANG_ENABLE_MODULES = YES; 580 | CLANG_ENABLE_OBJC_ARC = YES; 581 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 582 | CLANG_WARN_BOOL_CONVERSION = YES; 583 | CLANG_WARN_COMMA = YES; 584 | CLANG_WARN_CONSTANT_CONVERSION = YES; 585 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 586 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 587 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 588 | CLANG_WARN_EMPTY_BODY = YES; 589 | CLANG_WARN_ENUM_CONVERSION = YES; 590 | CLANG_WARN_INFINITE_RECURSION = YES; 591 | CLANG_WARN_INT_CONVERSION = YES; 592 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 593 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 594 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 595 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 596 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 597 | CLANG_WARN_STRICT_PROTOTYPES = YES; 598 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 599 | CLANG_WARN_SUSPICIOUS_MOVES = YES; 600 | CLANG_WARN_UNREACHABLE_CODE = YES; 601 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 602 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 603 | COPY_PHASE_STRIP = NO; 604 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 605 | ENABLE_NS_ASSERTIONS = NO; 606 | ENABLE_STRICT_OBJC_MSGSEND = YES; 607 | GCC_C_LANGUAGE_STANDARD = gnu99; 608 | GCC_NO_COMMON_BLOCKS = YES; 609 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 610 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 611 | GCC_WARN_UNDECLARED_SELECTOR = YES; 612 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 613 | GCC_WARN_UNUSED_FUNCTION = YES; 614 | GCC_WARN_UNUSED_VARIABLE = YES; 615 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 616 | MTL_ENABLE_DEBUG_INFO = NO; 617 | SDKROOT = iphoneos; 618 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 619 | SWIFT_VERSION = ""; 620 | VALIDATE_PRODUCT = YES; 621 | }; 622 | name = Release; 623 | }; 624 | 36A447EC1DE02BAA00DC48CE /* Debug */ = { 625 | isa = XCBuildConfiguration; 626 | buildSettings = { 627 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 628 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 629 | DEVELOPMENT_TEAM = 3CCNMX7TC9; 630 | INFOPLIST_FILE = RapidFireSample/Info.plist; 631 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 632 | PRODUCT_BUNDLE_IDENTIFIER = com.keygraphix.ios.RapidFireSample; 633 | PRODUCT_NAME = "$(TARGET_NAME)"; 634 | SWIFT_VERSION = 5.0; 635 | }; 636 | name = Debug; 637 | }; 638 | 36A447ED1DE02BAA00DC48CE /* Release */ = { 639 | isa = XCBuildConfiguration; 640 | buildSettings = { 641 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 642 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 643 | DEVELOPMENT_TEAM = 3CCNMX7TC9; 644 | INFOPLIST_FILE = RapidFireSample/Info.plist; 645 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 646 | PRODUCT_BUNDLE_IDENTIFIER = com.keygraphix.ios.RapidFireSample; 647 | PRODUCT_NAME = "$(TARGET_NAME)"; 648 | SWIFT_VERSION = 5.0; 649 | }; 650 | name = Release; 651 | }; 652 | 36A4480B1DE02BF800DC48CE /* Debug */ = { 653 | isa = XCBuildConfiguration; 654 | buildSettings = { 655 | CLANG_ENABLE_MODULES = YES; 656 | CODE_SIGN_IDENTITY = ""; 657 | CURRENT_PROJECT_VERSION = 1; 658 | DEFINES_MODULE = YES; 659 | DEVELOPMENT_TEAM = 3CCNMX7TC9; 660 | DYLIB_COMPATIBILITY_VERSION = 1; 661 | DYLIB_CURRENT_VERSION = 1; 662 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 663 | INFOPLIST_FILE = RapidFire/Info.plist; 664 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 665 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 666 | PRODUCT_BUNDLE_IDENTIFIER = com.keygraphix.ios.RapidFire; 667 | PRODUCT_NAME = "$(TARGET_NAME)"; 668 | SKIP_INSTALL = YES; 669 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 670 | SWIFT_VERSION = 5.0; 671 | TARGETED_DEVICE_FAMILY = "1,2"; 672 | VERSIONING_SYSTEM = "apple-generic"; 673 | VERSION_INFO_PREFIX = ""; 674 | }; 675 | name = Debug; 676 | }; 677 | 36A4480C1DE02BF800DC48CE /* Release */ = { 678 | isa = XCBuildConfiguration; 679 | buildSettings = { 680 | CLANG_ENABLE_MODULES = YES; 681 | CODE_SIGN_IDENTITY = ""; 682 | CURRENT_PROJECT_VERSION = 1; 683 | DEFINES_MODULE = YES; 684 | DEVELOPMENT_TEAM = 3CCNMX7TC9; 685 | DYLIB_COMPATIBILITY_VERSION = 1; 686 | DYLIB_CURRENT_VERSION = 1; 687 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 688 | INFOPLIST_FILE = RapidFire/Info.plist; 689 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 690 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 691 | PRODUCT_BUNDLE_IDENTIFIER = com.keygraphix.ios.RapidFire; 692 | PRODUCT_NAME = "$(TARGET_NAME)"; 693 | SKIP_INSTALL = YES; 694 | SWIFT_VERSION = 5.0; 695 | TARGETED_DEVICE_FAMILY = "1,2"; 696 | VERSIONING_SYSTEM = "apple-generic"; 697 | VERSION_INFO_PREFIX = ""; 698 | }; 699 | name = Release; 700 | }; 701 | 36A4480F1DE02BF800DC48CE /* Debug */ = { 702 | isa = XCBuildConfiguration; 703 | buildSettings = { 704 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 705 | DEVELOPMENT_TEAM = 3CCNMX7TC9; 706 | INFOPLIST_FILE = RapidFireTests/Info.plist; 707 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 708 | PRODUCT_BUNDLE_IDENTIFIER = com.keygraphix.ios.RapidFireTests; 709 | PRODUCT_NAME = "$(TARGET_NAME)"; 710 | SWIFT_SWIFT3_OBJC_INFERENCE = Default; 711 | SWIFT_VERSION = 5.0; 712 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/RapidFireSample.app/RapidFireSample"; 713 | }; 714 | name = Debug; 715 | }; 716 | 36A448101DE02BF800DC48CE /* Release */ = { 717 | isa = XCBuildConfiguration; 718 | buildSettings = { 719 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 720 | DEVELOPMENT_TEAM = 3CCNMX7TC9; 721 | INFOPLIST_FILE = RapidFireTests/Info.plist; 722 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 723 | PRODUCT_BUNDLE_IDENTIFIER = com.keygraphix.ios.RapidFireTests; 724 | PRODUCT_NAME = "$(TARGET_NAME)"; 725 | SWIFT_SWIFT3_OBJC_INFERENCE = Default; 726 | SWIFT_VERSION = 5.0; 727 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/RapidFireSample.app/RapidFireSample"; 728 | }; 729 | name = Release; 730 | }; 731 | /* End XCBuildConfiguration section */ 732 | 733 | /* Begin XCConfigurationList section */ 734 | 36A447D41DE02BAA00DC48CE /* Build configuration list for PBXProject "RapidFireSample" */ = { 735 | isa = XCConfigurationList; 736 | buildConfigurations = ( 737 | 36A447E91DE02BAA00DC48CE /* Debug */, 738 | 3612F1381DF6839F00BAB9FB /* Test */, 739 | 36A447EA1DE02BAA00DC48CE /* Release */, 740 | ); 741 | defaultConfigurationIsVisible = 0; 742 | defaultConfigurationName = Release; 743 | }; 744 | 36A447EB1DE02BAA00DC48CE /* Build configuration list for PBXNativeTarget "RapidFireSample" */ = { 745 | isa = XCConfigurationList; 746 | buildConfigurations = ( 747 | 36A447EC1DE02BAA00DC48CE /* Debug */, 748 | 3612F1391DF6839F00BAB9FB /* Test */, 749 | 36A447ED1DE02BAA00DC48CE /* Release */, 750 | ); 751 | defaultConfigurationIsVisible = 0; 752 | defaultConfigurationName = Release; 753 | }; 754 | 36A4480A1DE02BF800DC48CE /* Build configuration list for PBXNativeTarget "RapidFire" */ = { 755 | isa = XCConfigurationList; 756 | buildConfigurations = ( 757 | 36A4480B1DE02BF800DC48CE /* Debug */, 758 | 3612F13A1DF6839F00BAB9FB /* Test */, 759 | 36A4480C1DE02BF800DC48CE /* Release */, 760 | ); 761 | defaultConfigurationIsVisible = 0; 762 | defaultConfigurationName = Release; 763 | }; 764 | 36A4480E1DE02BF800DC48CE /* Build configuration list for PBXNativeTarget "RapidFireTests" */ = { 765 | isa = XCConfigurationList; 766 | buildConfigurations = ( 767 | 36A4480F1DE02BF800DC48CE /* Debug */, 768 | 3612F13B1DF6839F00BAB9FB /* Test */, 769 | 36A448101DE02BF800DC48CE /* Release */, 770 | ); 771 | defaultConfigurationIsVisible = 0; 772 | defaultConfigurationName = Release; 773 | }; 774 | /* End XCConfigurationList section */ 775 | }; 776 | rootObject = 36A447D11DE02BAA00DC48CE /* Project object */; 777 | } 778 | -------------------------------------------------------------------------------- /RapidFireSample.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /RapidFireSample.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /RapidFireSample.xcodeproj/xcshareddata/xcschemes/RapidFire.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 34 | 35 | 45 | 46 | 52 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 70 | 71 | 72 | 73 | 75 | 76 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /RapidFireSample.xcodeproj/xcshareddata/xcschemes/RapidFireSample.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 69 | 70 | 71 | 72 | 73 | 74 | 80 | 82 | 88 | 89 | 90 | 91 | 93 | 94 | 97 | 98 | 99 | -------------------------------------------------------------------------------- /RapidFireSample.xcodeproj/xcshareddata/xcschemes/RapidFireTests.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 29 | 35 | 36 | 37 | 43 | 49 | 50 | 51 | 52 | 53 | 58 | 59 | 61 | 67 | 68 | 69 | 70 | 71 | 77 | 78 | 79 | 80 | 81 | 82 | 92 | 93 | 94 | 95 | 101 | 102 | 104 | 105 | 108 | 109 | 110 | -------------------------------------------------------------------------------- /RapidFireSample/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // RapidFireSample 4 | // 5 | // Created by keygx on 2016/11/19. 6 | // Copyright © 2016年 keygx. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { 17 | // Override point for customization after application launch. 18 | return true 19 | } 20 | 21 | func applicationWillResignActive(_ application: UIApplication) { 22 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 23 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 24 | } 25 | 26 | func applicationDidEnterBackground(_ application: UIApplication) { 27 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 28 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 29 | } 30 | 31 | func applicationWillEnterForeground(_ application: UIApplication) { 32 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 33 | } 34 | 35 | func applicationDidBecomeActive(_ application: UIApplication) { 36 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 37 | } 38 | 39 | func applicationWillTerminate(_ application: UIApplication) { 40 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /RapidFireSample/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /RapidFireSample/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /RapidFireSample/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 35 | 46 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /RapidFireSample/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.4.0 19 | CFBundleVersion 20 | 1.4.0 21 | LSRequiresIPhoneOS 22 | 23 | NSAppTransportSecurity 24 | 25 | NSAllowsArbitraryLoads 26 | 27 | 28 | UILaunchStoryboardName 29 | LaunchScreen 30 | UIMainStoryboardFile 31 | Main 32 | UIRequiredDeviceCapabilities 33 | 34 | armv7 35 | 36 | UISupportedInterfaceOrientations 37 | 38 | UIInterfaceOrientationPortrait 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /RapidFireSample/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // RapidFireSample 4 | // 5 | // Created by keygx on 2016/11/19. 6 | // Copyright © 2016年 keygx. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import RapidFire 11 | 12 | class ViewController: UIViewController { 13 | 14 | // CompletionHandler 15 | let handler = { (response: RapidFire.Response) in 16 | switch response.result { 17 | case .success: 18 | print("success:\n \(response.statusCode as Any): \(response.response as Any)") 19 | print(response.toDictionary()) 20 | case .failure: 21 | print("error:\n \(response.statusCode as Any): \(response.error as Any)") 22 | } 23 | } 24 | 25 | override func viewDidLoad() { 26 | super.viewDidLoad() 27 | } 28 | 29 | override func didReceiveMemoryWarning() { 30 | super.didReceiveMemoryWarning() 31 | } 32 | 33 | @IBAction func btnGetAction(_ sender: UIButton) { 34 | // GET with Query Parameters 35 | RapidFire(.get, "https://httpbin.org") 36 | .setPath("/get") 37 | .setQuery(["a":"1", "b":"2"]) 38 | .setCompletionHandler(handler) 39 | .fire() 40 | } 41 | 42 | @IBAction func btnPostAction(_ sender: UIButton) { 43 | // POST with Body Message 44 | RapidFire(.post, "https://httpbin.org") 45 | .setPath("/post") 46 | .setBody(["a":"1", "b":"2"]) 47 | .setCompletionHandler(handler) 48 | .fire() 49 | } 50 | 51 | @IBAction func btnPostJsonAction(_ sender: UIButton) { 52 | // POST with JSON 53 | RapidFire(.post, "https://httpbin.org") 54 | .setPath("/post") 55 | .setJSON(["a":"1", "b":"2"]) 56 | .setCompletionHandler(handler) 57 | .fire() 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /RapidFireTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /RapidFireTests/RequestTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // RequestTests.swift 3 | // RapidFireSample 4 | // 5 | // Created by keygx on 2016/11/25. 6 | // Copyright © 2016年 keygx. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | @testable import RapidFire 11 | 12 | class RequestTests: XCTestCase { 13 | 14 | var session = RapidFire() 15 | 16 | override func setUp() { 17 | super.setUp() 18 | } 19 | 20 | override func tearDown() { 21 | super.tearDown() 22 | } 23 | 24 | func test_createURLRequest_GET() { 25 | session.settings.baseUrl = "https://example.com" 26 | session.settings.path = "/get" 27 | session.settings.query = ["a":"1", "b":"2"] 28 | session.settings.bodyParams = ["a":"2", "b":"3"] 29 | 30 | XCTAssertEqual(session.createURLRequest(.get, session.settings.baseUrl!)?.httpMethod, RapidFire.HTTPMethod.get.rawValue) 31 | XCTAssertEqual(session.createURLRequest(.get, session.settings.baseUrl!)?.url?.absoluteString, "https://example.com/get?b=2&a=1") 32 | } 33 | 34 | func test_createURLRequest_POST() { 35 | session.settings.baseUrl = "https://example.com" 36 | session.settings.path = "/post" 37 | session.settings.query = ["a":"1", "b":"2"] 38 | session.settings.bodyParams = ["a":"2", "b":"3"] 39 | 40 | XCTAssertEqual(session.createURLRequest(.post, session.settings.baseUrl!)?.httpMethod, RapidFire.HTTPMethod.post.rawValue) 41 | XCTAssertEqual(session.createURLRequest(.post, session.settings.baseUrl!)?.url?.absoluteString, "https://example.com/post") 42 | XCTAssertEqual(session.createURLRequest(.post, session.settings.baseUrl!)?.httpBody, "b=3&a=2".data(using: String.Encoding.utf8)) 43 | } 44 | 45 | func test_createURLRequest_PUT() { 46 | session.settings.baseUrl = "https://example.com" 47 | session.settings.path = "/put" 48 | session.settings.query = ["a":"1", "b":"2"] 49 | session.settings.bodyParams = ["a":"2", "b":"3"] 50 | 51 | XCTAssertEqual(session.createURLRequest(.put, session.settings.baseUrl!)?.httpMethod, RapidFire.HTTPMethod.put.rawValue) 52 | XCTAssertEqual(session.createURLRequest(.put, session.settings.baseUrl!)?.url?.absoluteString, "https://example.com/put") 53 | XCTAssertEqual(session.createURLRequest(.put, session.settings.baseUrl!)?.httpBody, "b=3&a=2".data(using: String.Encoding.utf8)) 54 | } 55 | 56 | func test_createURLRequest_PATCH() { 57 | session.settings.baseUrl = "https://example.com" 58 | session.settings.path = "/patch" 59 | session.settings.query = ["a":"1", "b":"2"] 60 | session.settings.bodyParams = ["a":"2", "b":"3"] 61 | 62 | XCTAssertEqual(session.createURLRequest(.patch, session.settings.baseUrl!)?.httpMethod, RapidFire.HTTPMethod.patch.rawValue) 63 | XCTAssertEqual(session.createURLRequest(.patch, session.settings.baseUrl!)?.url?.absoluteString, "https://example.com/patch") 64 | XCTAssertEqual(session.createURLRequest(.patch, session.settings.baseUrl!)?.httpBody, "b=3&a=2".data(using: String.Encoding.utf8)) 65 | } 66 | 67 | func test_createURLRequest_DELETE_Query() { 68 | session.settings.baseUrl = "https://example.com" 69 | session.settings.path = "/delete" 70 | session.settings.query = ["a":"1", "b":"2"] 71 | 72 | XCTAssertEqual(session.createURLRequest(.delete, session.settings.baseUrl!)?.httpMethod, RapidFire.HTTPMethod.delete.rawValue) 73 | XCTAssertEqual(session.createURLRequest(.delete, session.settings.baseUrl!)?.url?.absoluteString, "https://example.com/delete?b=2&a=1") 74 | } 75 | 76 | func test_createURLRequest_DELETE_Body() { 77 | session.settings.baseUrl = "https://example.com" 78 | session.settings.path = "/delete" 79 | session.settings.bodyParams = ["a":"2", "b":"3"] 80 | 81 | XCTAssertEqual(session.createURLRequest(.delete, session.settings.baseUrl!)?.httpMethod, RapidFire.HTTPMethod.delete.rawValue) 82 | XCTAssertEqual(session.createURLRequest(.delete, session.settings.baseUrl!)?.url?.absoluteString, "https://example.com/delete") 83 | XCTAssertEqual(session.createURLRequest(.delete, session.settings.baseUrl!)?.httpBody, "b=3&a=2".data(using: String.Encoding.utf8)) 84 | } 85 | 86 | func test_createURLRequest_Multipart() { 87 | session.settings.baseUrl = "https://example.com/multipart" 88 | session.settings.partDataParams = ["a":"1", "b":"2"] 89 | let filePath = Bundle(for: type(of: self)).path(forResource: "circle", ofType: "png") 90 | let imageData = try! Data(contentsOf: URL(fileURLWithPath: filePath!)) 91 | session.settings.partDataBinary?.append(RapidFire.PartData(name: "image", filename: "circle.png", value: imageData, mimeType: "image/png")) 92 | let request = session.createURLRequest(.post, session.settings.baseUrl!) 93 | 94 | XCTAssertEqual(request?.httpMethod, RapidFire.HTTPMethod.post.rawValue) 95 | XCTAssertEqual(request?.url?.absoluteString, "https://example.com/multipart") 96 | XCTAssertEqual(request?.httpBody, session.buildMultipartFormData(request: request!, params: session.settings.partDataParams, partData: session.settings.partDataBinary) as Data) 97 | } 98 | 99 | func test_createURLRequest_TimeoutInterval() { 100 | session.settings.baseUrl = "https://example.com" 101 | session.settings.path = "/get" 102 | session.settings.timeoutInterval = 15 103 | 104 | XCTAssertEqual(session.createURLRequest(.get, session.settings.baseUrl!)?.timeoutInterval, 15) 105 | } 106 | 107 | func test_addHeaders() { 108 | let headers = ["Content-Type":"image/jpeg", "MyCustom":"value"] 109 | session.settings.headers = headers 110 | let urlRequest = URLRequest(url: URL(string: "https://example.com")!) 111 | let request = session.addHeaders(request: urlRequest) 112 | 113 | XCTAssertEqual(request.allHTTPHeaderFields?.count, 2) 114 | XCTAssertEqual(request.allHTTPHeaderFields?["Content-Type"], "image/jpeg") 115 | XCTAssertEqual(request.allHTTPHeaderFields?["MyCustom"], "value") 116 | } 117 | 118 | func test_buildQueryParameters() { 119 | let params = ["b":"2", "a":"1"] 120 | session.settings.method = .get 121 | 122 | XCTAssertEqual(session.buildQueryParameters(parameters: params), "b=2&a=1") 123 | XCTAssertNil(session.buildQueryParameters(parameters: nil)) 124 | } 125 | 126 | func test_buildBodyParameters() { 127 | let params = ["b":"2", "a":"1"] 128 | session.settings.method = .post 129 | 130 | XCTAssertEqual(session.buildBodyParameters(parameters: params), "b=2&a=1") 131 | XCTAssertNil(session.buildBodyParameters(parameters: nil)) 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /RapidFireTests/SettingTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SettingTests.swift 3 | // RapidFireSample 4 | // 5 | // Created by keygx on 2016/11/25. 6 | // Copyright © 2016年 keygx. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | @testable import RapidFire 11 | 12 | class SettingTests: XCTestCase { 13 | 14 | var session = RapidFire() 15 | 16 | override func setUp() { 17 | super.setUp() 18 | } 19 | 20 | override func tearDown() { 21 | super.tearDown() 22 | } 23 | 24 | func test_Setting() { 25 | let method = RapidFire.HTTPMethod.get 26 | let baseUrl = "https://example.com" 27 | let path = "/get" 28 | let headers = ["MyHeader":"MyHeader"] 29 | let query = ["a":"1", "b":"2"] 30 | let body = ["c":"3", "d":"4"] 31 | let json = ["a":"1", "b":"2", "c":"3", "d":"4"] 32 | let partDataParams = ["e":"5", "f":"6"] 33 | let filePath = Bundle(for: type(of: self)).path(forResource: "circle", ofType: "png") 34 | let imageData = try! Data(contentsOf: URL(fileURLWithPath: filePath!)) 35 | let partDataBinary = RapidFire.PartData(name: "image", filename: "circle.png", value: imageData, mimeType: "image/png") 36 | 37 | session = RapidFire(method, baseUrl) 38 | session 39 | .setPath(path) 40 | .setHeaders(headers) 41 | .setQuery(query) 42 | .setBody(body) 43 | .setJSON(json) 44 | .setPartData(partDataParams) 45 | .setPartData(partDataBinary) 46 | .setTimeout(15) 47 | .setRetry(3, intervalSec: 30) 48 | .setCompletionHandler({ (response: RapidFire.Response) in }) 49 | .fire() 50 | 51 | XCTAssertEqual(session.settings.method, method) 52 | XCTAssertEqual(session.settings.baseUrl, baseUrl) 53 | XCTAssertEqual(session.settings.path, path) 54 | XCTAssertEqual(session.settings.headers!, headers) 55 | XCTAssertEqual(session.settings.query!, query) 56 | XCTAssertEqual(session.settings.bodyParams!, body) 57 | XCTAssertEqual(session.settings.json?["a"] as! String, "1") 58 | XCTAssertEqual(session.settings.json?["b"] as! String, "2") 59 | XCTAssertEqual(session.settings.json?["c"] as! String, "3") 60 | XCTAssertEqual(session.settings.json?["d"] as! String, "4") 61 | XCTAssertEqual(session.settings.partDataParams?["e"], "5") 62 | XCTAssertEqual(session.settings.partDataParams?["f"], "6") 63 | XCTAssertEqual(session.settings.partDataBinary?.first?.name, "image") 64 | XCTAssertEqual(session.settings.partDataBinary?.first?.filename, "circle.png") 65 | XCTAssertEqual(session.settings.partDataBinary?.first?.value, imageData) 66 | XCTAssertEqual(session.settings.partDataBinary?.first?.mimeType, "image/png") 67 | XCTAssertEqual(session.settings.timeoutInterval, 15) 68 | XCTAssertEqual(session.settings.retryCount, 3) 69 | XCTAssertEqual(session.settings.retryInterval, 30) 70 | XCTAssertNotNil(session.settings.completionHandler) 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /RapidFireTests/UtilTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // UtilTests.swift 3 | // RapidFireTests 4 | // 5 | // Created by keygx on 2016/11/19. 6 | // Copyright © 2016年 keygx. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | @testable import RapidFire 11 | 12 | class UtilTests: XCTestCase { 13 | 14 | override func setUp() { 15 | super.setUp() 16 | } 17 | 18 | override func tearDown() { 19 | super.tearDown() 20 | } 21 | 22 | func test_toJsonDictionary() { 23 | let json: [String: Any] = ["a":1, "b":"あ"] 24 | let testData = try! JSONSerialization.data(withJSONObject: json, options: .prettyPrinted) 25 | 26 | XCTAssertEqual(RapidFire.Util.toDictionary(from: testData)["a"] as? Int, 1) 27 | XCTAssertEqual(RapidFire.Util.toDictionary(from: testData)["b"] as? String, "あ") 28 | XCTAssertEqual(RapidFire.Util.toDictionary(from: nil).count, 0) 29 | XCTAssertNotEqual(RapidFire.Util.toDictionary(from: testData)["a"] as? Int, 1000) 30 | XCTAssertNotEqual(RapidFire.Util.toDictionary(from: testData)["b"] as? String, "ん") 31 | } 32 | 33 | func test_toJsonArray() { 34 | let json: [[String: Any]] = [["a":1, "b":"あ"], ["a":1000, "b":"い"]] 35 | let testData = try! JSONSerialization.data(withJSONObject: json, options: .prettyPrinted) 36 | 37 | XCTAssertEqual(RapidFire.Util.toArray(from: testData)[0]["a"] as? Int, 1) 38 | XCTAssertEqual(RapidFire.Util.toArray(from: testData)[0]["b"] as? String, "あ") 39 | XCTAssertEqual(RapidFire.Util.toArray(from: testData)[1]["a"] as? Int, 1000) 40 | XCTAssertEqual(RapidFire.Util.toArray(from: testData)[1]["b"] as? String, "い") 41 | XCTAssertEqual(RapidFire.Util.toArray(from: nil).count, 0) 42 | XCTAssertNotEqual(RapidFire.Util.toArray(from: testData)[0]["a"] as? Int, 1000) 43 | XCTAssertNotEqual(RapidFire.Util.toArray(from: testData)[0]["b"] as? String, "ん") 44 | } 45 | 46 | func test_toString() { 47 | let str = "RapidFire" 48 | let testData = str.data(using: String.Encoding.utf8) 49 | 50 | XCTAssertEqual(RapidFire.Util.toString(from: testData), str) 51 | XCTAssertEqual(RapidFire.Util.toString(from: nil), "") 52 | XCTAssertNotEqual(RapidFire.Util.toString(from: testData), "foo bar") 53 | } 54 | 55 | func test_toJSON() { 56 | let testData: [[String: Any]] = [["a":1, "b":"あ"], ["a":1000, "b":"い"]] 57 | let json = try! JSONSerialization.data(withJSONObject: testData, options: .prettyPrinted) 58 | 59 | XCTAssertEqual(RapidFire.Util.toJSON(from: testData), json) 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /RapidFireTests/images/circle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keygx/RapidFire/3faa98723e81dac4068911d5d31d8ab8e3f91138/RapidFireTests/images/circle.png --------------------------------------------------------------------------------