<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.0.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/URLCredential/init(user:password:persistence:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSURLCredential(im)initWithUser:password:persistence:"
  },
  "title" : "init(user:password:persistence:)"
}
-->

# init(user:password:persistence:)

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

```
init(user: String, password: String, persistence: URLCredential.Persistence)
```

## Parameters

`user`

The user for the credential.

`password`

The password for `user`.

`persistence`

A [`URLCredential.Persistence`](/documentation/Foundation/URLCredential/Persistence-swift.enum) value indicating whether the credential should be stored permanently, for the duration of the current session, or not at all.

## Return Value

An instance of [`URLCredential`](/documentation/Foundation/URLCredential), initialized with user name `user`, password `password`, and using persistence setting `persistence`.

## Discussion

If `persistence` is [`URLCredential.Persistence.permanent`](/documentation/Foundation/URLCredential/Persistence-swift.enum/permanent), the credential is stored in the keychain. If `persistence` is [`URLCredential.Persistence.synchronizable`](/documentation/Foundation/URLCredential/Persistence-swift.enum/synchronizable), it is also stored to the user’s other devices.

## See Also

[`+  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.



---

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)