Instance Method

urlSession(_:dataTask:didReceive:)

Tells the delegate that the data task has received some of the expected data.

Declaration

optional func urlSession(_ session: URLSession, dataTask: URLSessionDataTask, didReceive data: Data)

Parameters

session

The session containing the data task that provided data.

dataTask

The data task that provided data.

data

A data object containing the transferred data.

Discussion

Because the NSData object is often pieced together from a number of different data objects, whenever possible, use NSData’s enumerateBytes(_:) method to iterate through the data rather than using the bytes method (which flattens the NSData object into a single memory block).

This delegate method may be called more than once, and each call provides only data received since the previous call. The app is responsible for accumulating this data if needed.