<!--
{
  "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/URLCredential",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSURLCredential"
  },
  "title" : "URLCredential"
}
-->

# URLCredential

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

```
class URLCredential
```

## 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 ``doc://com.apple.foundation/documentation/Foundation/URLCredentialStorage``. In general, use for-session persistence for TLS credentials.

## Topics

### Creating a credential

[`init(forTrust:)`](/documentation/Foundation/URLCredential/init(forTrust:))

Creates a URL credential instance for server trust authentication with a given accepted trust.

[`+  credentialWithUser:password:persistence:`](/documentation/Foundation/NSURLCredential/credentialWithUser:password:persistence:)

Creates a URL credential instance for internet password authentication with a given user name and password, using a given persistence setting.

[`+  credentialWithIdentity:certificates:persistence:`](/documentation/Foundation/NSURLCredential/credentialWithIdentity:certificates:persistence:)

Creates a URL credential instance for resolving a client certificate authentication challenge.

[`-  initWithIdentity:certificates:persistence:`](/documentation/Foundation/URLCredential/init(identity:certificates:persistence:))

Creates a URL credential instance for resolving a client certificate authentication challenge.

[`-  initWithTrust:`](/documentation/Foundation/URLCredential/init(trust:))

Creates a URL credential instance for server trust authentication, initialized with a accepted trust.

[`-  initWithUser:password:persistence:`](/documentation/Foundation/URLCredential/init(user:password:persistence:))

Creates a URL credential instance initialized with a given user name and password, using a given persistence setting.

[`Persistence`](/documentation/Foundation/URLCredential/Persistence-swift.enum)

Constants that specify how long the credential will be kept.

### Getting credential properties

[`user`](/documentation/Foundation/URLCredential/user)

The credential’s user name.

[`certificates`](/documentation/Foundation/URLCredential/certificates)

The intermediate certificates of the credential, if it is a client certificate credential.

[`hasPassword`](/documentation/Foundation/URLCredential/hasPassword)

A Boolean value that indicates whether the credential has a password.

[`password`](/documentation/Foundation/URLCredential/password)

The credential’s password.

[`identity`](/documentation/Foundation/URLCredential/identity)

The identity of this credential if it is a client certificate credential.

[`persistence`](/documentation/Foundation/URLCredential/persistence-swift.property)

The credential’s persistence setting.

[`Persistence`](/documentation/Foundation/URLCredential/Persistence-swift.enum)

Constants that specify how long the credential will be kept.

## Relationships

### Conforms To

[`Hashable`](/documentation/Swift/Hashable)

[`CVarArg`](/documentation/Swift/CVarArg)

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

[`NSCopying`](/documentation/Foundation/NSCopying)

[`NSSecureCoding`](/documentation/Foundation/NSSecureCoding)

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

[`Equatable`](/documentation/Swift/Equatable)

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

[`NSCoding`](/documentation/Foundation/NSCoding)

[`Sendable`](/documentation/Swift/Sendable)

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

### Inherits From

[`NSObject-swift.class`](/documentation/ObjectiveC/NSObject-swift.class)

---

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)