<!--
{
  "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",
  "metadataVersion" : "0.1.0",
  "role" : "Protocol",
  "symbol" : {
    "kind" : "Protocol",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(pl)NSURLConnectionDataDelegate"
  },
  "title" : "NSURLConnectionDataDelegate"
}
-->

# NSURLConnectionDataDelegate

A protocol that most delegates of a URL connection implement to receive data associated with the connection.

```
protocol NSURLConnectionDataDelegate : NSURLConnectionDelegate
```

## Overview

The `NSURLConnectionDataDelegate` protocol describes methods that should be implemented by the delegate for an instance of the [`NSURLConnection`](/documentation/Foundation/NSURLConnection) class. Many methods in this protocol existed as part of an informal protocol in previous versions of macOS and iOS.

In addition to the methods described in this protocol, an `NSURLConnection` delegate should also implement the methods described in the [`NSURLConnectionDelegate`](/documentation/Foundation/NSURLConnectionDelegate) protocol.

> Note:
> If you are using `NSURLConnection` as part of Newsstand Kit on iOS, you should also implement the methods in the ``doc://com.apple.foundation/documentation/Foundation/NSURLConnectionDownloadDelegate`` protocol.

## Topics

### Handling Incoming Data

[`connection(_:didReceive:)`](/documentation/Foundation/NSURLConnectionDataDelegate/connection(_:didReceive:)-8t66w)

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

[`connection(_:didReceive:)`](/documentation/Foundation/NSURLConnectionDataDelegate/connection(_:didReceive:)-8p5vg)

Sent as a connection loads data incrementally.

### Receiving Connection Progress

[`connection(_:didSendBodyData:totalBytesWritten:totalBytesExpectedToWrite:)`](/documentation/Foundation/NSURLConnectionDataDelegate/connection(_:didSendBodyData:totalBytesWritten:totalBytesExpectedToWrite:))

Sent as the body (message data) of a request is transmitted (such as in an HTTP POST request).

[`connectionDidFinishLoading(_:)`](/documentation/Foundation/NSURLConnectionDataDelegate/connectionDidFinishLoading(_:))

Sent when a connection has finished loading successfully.

### Handling Redirects

[`connection(_:willSend:redirectResponse:)`](/documentation/Foundation/NSURLConnectionDataDelegate/connection(_:willSend:redirectResponse:))

Sent when the connection determines that it must change URLs in order to continue loading a request.

[`connection(_:needNewBodyStream:)`](/documentation/Foundation/NSURLConnectionDataDelegate/connection(_:needNewBodyStream:))

Called when an `NSURLConnection` needs to retransmit a request that has a body stream to provide a new, unopened stream.

### Overriding Caching Behavior

[`connection(_:willCacheResponse:)`](/documentation/Foundation/NSURLConnectionDataDelegate/connection(_:willCacheResponse:))

Sent before the connection stores a cached response in the cache, to give the delegate an opportunity to alter it.



---

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)