Nuke Documentation

Class Data​Loader

public final class DataLoader: DataLoading, _DataLoaderObserving  

Provides basic networking using URLSession.

DataLoader DataLoader DataLoading DataLoading DataLoader->DataLoading _DataLoaderObserving _DataLoaderObserving DataLoader->_DataLoaderObserving

Nested Types

DataLoader.Error

Errors produced by DataLoader.

Conforms To

DataLoading

Fetches original image data.

Initializers

init(configuration:​validate:​)

public init(configuration: URLSessionConfiguration = DataLoader.defaultConfiguration,
                validate: @escaping (URLResponse) -> Swift.Error? = DataLoader.validate)  

Initializes DataLoader with the given configuration.

Parameters

configuration URLSession​Configuration

URLSessionConfiguration.default with URLCache with 0 MB memory capacity and 150 MB disk capacity.

Properties

session

public let session: URLSession

observer

public var observer: DataLoaderObserving? 

default​Configuration

public static var defaultConfiguration: URLSessionConfiguration  

Returns a default configuration which has a sharedUrlCache set as a urlCache.

shared​Url​Cache

public static let sharedUrlCache: URLCache  

Shared url cached used by a default DataLoader. The cache is initialized with 0 MB memory capacity and 150 MB disk capacity.

Methods

validate(response:​)

public static func validate(response: URLResponse) -> Swift.Error?  

Validates HTTP responses by checking that the status code is 2xx. If it's not returns DataLoader.Error.statusCodeUnacceptable.

load​Data(with:​did​Receive​Data:​completion:​)

public func loadData(with request: URLRequest,
                         didReceiveData: @escaping (Data, URLResponse) -> Void,
                         completion: @escaping (Swift.Error?) -> Void) -> Cancellable