---
title: "connection(_:didReceive:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/nsurlconnectiondatadelegate/connection(_:didreceive:)-8t66w"
---

# connection(_:didReceive:)

Sent when the connection has received sufficient data to construct the URL response for its request.

## Declaration

```swift
optional func connection(_ connection: NSURLConnection, didReceive response: URLResponse)
```

## Parameters

- `connection`: The connection sending the message.
- `response`: The URL response for the connection’s request. This object is immutable and will not be modified by the URL loading system once it is presented to the delegate.

## Discussion

Discussion In rare cases, for example in the case of an HTTP load where the content type of the load data is multipart/x-mixed-replace, the delegate will receive more than one connection:didReceiveResponse: message. When this happens, discard (or process) all data previously delivered by connection:didReceiveData:, and prepare to handle the next part (which could potentially have a different MIME type). The only case where this message is not sent to the delegate is when the protocol implementation encounters an error before a response could be created.

## See Also

### Related Documentation

- [URL Loading System](foundation/url-loading-system.md)

### Handling Incoming Data

- [connection(_:didReceive:)](foundation/nsurlconnectiondatadelegate/connection(_:didreceive:)-8p5vg.md)
