---
title: NSURLConnectionDelegate
framework: foundation
role: symbol
role_heading: Protocol
path: foundation/nsurlconnectiondelegate
---

# NSURLConnectionDelegate

A protocol that delegates of a URL connection implement to receive status about and provide feedback to the connection object.

## Declaration

```swift
protocol NSURLConnectionDelegate : NSObjectProtocol
```

## Overview

Overview Delegates of NSURLConnection objects should implement either the NSURLConnectionDataDelegate or NSURLConnectionDownloadDelegate protocol in addition to the NSURLConnectionDelegate protocol. Specifically: If you are using NSURLConnection in conjunction with Newsstand Kit’s download(with:) method, the delegate class should implement the NSURLConnectionDownloadDelegate protocol. Otherwise, the delegate class should implement the NSURLConnectionDataDelegate protocol. Delegates that wish to perform custom authentication handling should implement the connection(_:willSendRequestFor:) method, which is the preferred mechanism for responding to authentication challenges. (See URLAuthenticationChallenge for more information on authentication challenges.) If connection(_:willSendRequestFor:) is not implemented, the older, deprecated methods connection(_:canAuthenticateAgainstProtectionSpace:), connection(_:didReceive:), and connection(_:didCancel:) are called instead. The connection(_:didFailWithError:) method is called at most once if an error occurs during the loading of a resource. The connectionShouldUseCredentialStorage(_:) method is called once, just before the loading of a resource begins.

## Topics

### Connection Authentication

- [connection(_:willSendRequestFor:)](foundation/nsurlconnectiondelegate/connection(_:willsendrequestfor:).md)
- [connection(_:canAuthenticateAgainstProtectionSpace:)](foundation/nsurlconnectiondelegate/connection(_:canauthenticateagainstprotectionspace:).md)
- [connection(_:didCancel:)](foundation/nsurlconnectiondelegate/connection(_:didcancel:).md)
- [connection(_:didReceive:)](foundation/nsurlconnectiondelegate/connection(_:didreceive:).md)
- [connectionShouldUseCredentialStorage(_:)](foundation/nsurlconnectiondelegate/connectionshouldusecredentialstorage(_:).md)

### Connection Completion

- [connection(_:didFailWithError:)](foundation/nsurlconnectiondelegate/connection(_:didfailwitherror:).md)

## Relationships

### Inherits From

- [NSObjectProtocol](objectivec/nsobjectprotocol.md)

### Inherited By

- [NSURLConnectionDataDelegate](foundation/nsurlconnectiondatadelegate.md)
- [NSURLConnectionDownloadDelegate](foundation/nsurlconnectiondownloaddelegate.md)

## See Also

### URL Connection

- [NSURLConnection](foundation/nsurlconnection.md)
- [NSURLConnectionDataDelegate](foundation/nsurlconnectiondatadelegate.md)
- [NSURLConnectionDownloadDelegate](foundation/nsurlconnectiondownloaddelegate.md)
