---
title: "init(user:password:persistence:)"
framework: foundation
role: symbol
role_heading: Initializer
path: "foundation/urlcredential/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.

## Declaration

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

## Parameters

- `user`: The user for the credential.
- `password`: The password for user.
- `persistence`: A doc://com.apple.foundation/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

Return Value An instance of URLCredential, initialized with user name user, password password, and using persistence setting persistence.

## Discussion

Discussion If persistence is URLCredential.Persistence.permanent, the credential is stored in the keychain. If persistence is URLCredential.Persistence.synchronizable, it is also stored to the user’s other devices.

## See Also

### 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)
- [URLCredential.Persistence](foundation/urlcredential/persistence-swift.enum.md)
