---
title: URLCredentialStorage
framework: foundation
role: symbol
role_heading: Class
path: foundation/urlcredentialstorage
---

# URLCredentialStorage

The manager of a shared credentials cache.

## Declaration

```swift
class URLCredentialStorage
```

## Overview

Overview The shared cache stores and retrieves instances of URLCredential. You can store password-based credentials permanently, based on the URLCredential.Persistence they were created with. Certificate-based credentials are never stored permanently. Subclassing notes The URLCredentialStorage class is meant to be used as-is, but you can subclass it if you have specific needs, such as screening which credentials are stored. When overriding methods of this class, be aware that methods that take a task parameter are preferred to equivalent methods that do not. Therefore, you should override the task-based methods when subclassing, as follows: Setting credentials — Override set(_:for:task:) instead of or in addition to set(_:for:). Getting credentials — Override getCredentials(for:task:completionHandler:) instead of or in addition to credentials(for:). Removing credentials — Override remove(_:for:options:task:) instead of or in addition to remove(_:for:options:) and remove(_:for:). Setting default credentials — Override setDefaultCredential(_:for:task:) instead of or in addition to setDefaultCredential(_:for:). Getting default credentials — Override getDefaultCredential(for:task:completionHandler:) instead of or in addition to defaultCredential(for:).

## Topics

### Getting the credential storage

- [shared](foundation/urlcredentialstorage/shared.md)

### Getting and setting default credentials

- [defaultCredential(for:)](foundation/urlcredentialstorage/defaultcredential(for:).md)
- [getDefaultCredential(for:task:completionHandler:)](foundation/urlcredentialstorage/getdefaultcredential(for:task:completionhandler:).md)
- [setDefaultCredential(_:for:)](foundation/urlcredentialstorage/setdefaultcredential(_:for:).md)
- [setDefaultCredential(_:for:task:)](foundation/urlcredentialstorage/setdefaultcredential(_:for:task:).md)

### Adding and removing credentials

- [remove(_:for:)](foundation/urlcredentialstorage/remove(_:for:).md)
- [remove(_:for:options:)](foundation/urlcredentialstorage/remove(_:for:options:).md)
- [remove(_:for:options:task:)](foundation/urlcredentialstorage/remove(_:for:options:task:).md)
- [Dictionary key for credential removal options](foundation/dictionary-key-for-credential-removal-options.md)
- [set(_:for:)](foundation/urlcredentialstorage/set(_:for:).md)
- [set(_:for:task:)](foundation/urlcredentialstorage/set(_:for:task:).md)

### Retrieving credentials

- [allCredentials](foundation/urlcredentialstorage/allcredentials.md)
- [credentials(for:)](foundation/urlcredentialstorage/credentials(for:).md)
- [getCredentials(for:task:completionHandler:)](foundation/urlcredentialstorage/getcredentials(for:task:completionhandler:).md)

### Tracking credential storage changes

- [NSURLCredentialStorageChanged](foundation/nsnotification/name-swift.struct/nsurlcredentialstoragechanged.md)

## Relationships

### Inherits From

- [NSObject](objectivec/nsobject-swift.class.md)

### Conforms To

- [CVarArg](swift/cvararg.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Hashable](swift/hashable.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)
- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)

## See Also

### Authentication and credentials

- [Handling an authentication challenge](foundation/handling-an-authentication-challenge.md)
- [URLAuthenticationChallenge](foundation/urlauthenticationchallenge.md)
- [URLCredential](foundation/urlcredential.md)
- [URLProtectionSpace](foundation/urlprotectionspace.md)
