---
title: URLCredential
framework: foundation
role: symbol
role_heading: Class
path: foundation/urlcredential
---

# URLCredential

An authentication credential consisting of information specific to the type of credential and the type of persistent storage to use, if any.

## Declaration

```swift
class URLCredential
```

## Mentioned in

Performing manual server trust authentication

## Overview

Overview The URL Loading System supports password-based user credentials, certificate-based user credentials, and certificate-based server credentials. When you create a credential, you can specify it for a single request, persist it temporarily (until your app quits), or persist it permanently. Permanent persistence can be local persistence in the keychain, or synchronized persistence across the user’s devices, based on their Apple ID. note: Permanent storage of credentials is only available for password-based credentials. TLS credentials are never stored permanently by URLCredentialStorage. In general, use for-session persistence for TLS credentials.

## Topics

### Creating a credential

- [init(forTrust:)](foundation/urlcredential/init(fortrust:).md)
- [init(identity:certificates:persistence:)](foundation/urlcredential/init(identity:certificates:persistence:).md)
- [init(trust:)](foundation/urlcredential/init(trust:).md)
- [init(user:password:persistence:)](foundation/urlcredential/init(user:password:persistence:).md)
- [URLCredential.Persistence](foundation/urlcredential/persistence-swift.enum.md)

### Getting credential properties

- [user](foundation/urlcredential/user.md)
- [certificates](foundation/urlcredential/certificates.md)
- [hasPassword](foundation/urlcredential/haspassword.md)
- [password](foundation/urlcredential/password.md)
- [identity](foundation/urlcredential/identity.md)
- [persistence](foundation/urlcredential/persistence-swift.property.md)
- [URLCredential.Persistence](foundation/urlcredential/persistence-swift.enum.md)

### Initializers

- [init(coder:)](foundation/urlcredential/init(coder:).md)

### Default Implementations

- [NSURLCredential Implementations](foundation/urlcredential/nsurlcredential-implementations.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)
- [NSCoding](foundation/nscoding.md)
- [NSCopying](foundation/nscopying.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)
- [NSSecureCoding](foundation/nssecurecoding.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)
- [URLCredentialStorage](foundation/urlcredentialstorage.md)
- [URLProtectionSpace](foundation/urlprotectionspace.md)
