<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.2.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSURLConnectionDataDelegate/connection(_:didReceive:)-8t66w",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(pl)NSURLConnectionDataDelegate(im)connection:didReceiveResponse:"
  },
  "title" : "connection(_:didReceive:)"
}
-->

# connection(_:didReceive:)

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

```
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

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

[URL Loading System](/documentation/Foundation/url-loading-system)

Interact with URLs and communicate with servers using standard Internet protocols.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)