Swifty

@objc
final public class Swifty : NSObject

Swifty: The main entry point to the networking infrastructure. Keeps track of the constraints and interceptors and services the requests with it’s URLSession while taking care of all the attributes of the network resource.

  • Swifty’s shared instance: It’s highly recommended you create your own Swifty instances with your customizations (Constraints, Interceptors) instead of using the shared instance.

    Declaration

    Swift

    public static let shared: Swifty
  • Initialize Swifty with the given URLSession, Constraints, and Request & Response Interceptors

    The constraints and interceptors passed in these arguments will run in same order as passed in these arrays.

    Declaration

    Swift

    public init(session: URLSession,
                constraints: [Constraint] = [],
                requestInterceptors: [RequestInterceptor] = [],
                responseInterceptors: [ResponseInterceptor] = [])

    Parameters

    session

    URLSession

    constraints

    Array of Constraints.

    requestInterceptors

    Array of Request Interceptors.

    responseInterceptors

    Array of Response Interceptors.

  • Initialize Swifty with the given URLSessionConfiguration, Constraints, Request Interceptors & Response Interceptors

    The constraints and interceptors passed in these arguments will run in same order as passed in these arrays.

    Declaration

    Swift

    public convenience init(configuration: URLSessionConfiguration = URLSessionConfiguration.default,
                            constraints: [Constraint] = [],
                            requestInterceptors: [RequestInterceptor] = [],
                            responseInterceptors: [ResponseInterceptor] = [],
                            sessionMetricsDelegate: URLSessionTaskDelegate? = nil)

    Parameters

    configuration

    URLSessionConfiguration (Defaults to URLSessionConfiguration.default)

    constraints

    Array of Constraints.

    requestInterceptors

    Array of Request Interceptors.

    responseInterceptors

    Array of Response Interceptors.

  • Adds a network resource to run on the Swifty Queue.

    This is what is called internally when you use .load() method or any variant of the .load() method on a NetworkResource

    Declaration

    Swift

    public func add(_ resource: NetworkResource, successBlock: @escaping SwiftySuccessBlock, failureBlock: @escaping SwiftyFailureBlock)

    Parameters

    resource

    NetworkResource

    successBlock

    SwiftySuccessBlock

    failureBlock

    SwiftyFailureBlock