2 // OAuthSwiftResponse.swift
5 // Created by phimage on 04/11/16.
6 // Copyright © 2016 Dongri Jin. All rights reserved.
13 public class OAuthSwiftResponse: NSObject { // not a struct for objc
14 /// The data returned by the server.
16 /// The server's response to the URL request.
17 public var response: HTTPURLResponse
18 /// The URL request sent to the server.
19 public var request: URLRequest?
21 public init(data: Data, response: HTTPURLResponse, request: URLRequest?) {
23 self.response = response
24 self.request = request
29 /// Extends this object to convert data into your business objects
30 extension OAuthSwiftResponse {
32 public func dataString(encoding: String.Encoding = OAuthSwiftDataEncoding) -> String? {
33 return String(data: self.data, encoding: encoding)
36 /// `data` converted to string using data encoding
37 public var string: String? {
41 /// Convert to json object using JSONSerialization
42 public func jsonObject(options opt: JSONSerialization.ReadingOptions = []) throws -> Any {
43 return try JSONSerialization.jsonObject(with: self.data, options: opt)
46 /// Convert to object using PropertyListSerialization
47 public func propertyList(options opt: PropertyListSerialization.ReadOptions = [], format: UnsafeMutablePointer<PropertyListSerialization.PropertyListFormat>? = nil) throws -> Any {
48 return try PropertyListSerialization.propertyList(from: self.data, options: opt, format: format)