---
title: "setCredential(_:type:)"
framework: localauthentication
role: symbol
role_heading: Instance Method
path: "localauthentication/lacontext/setcredential(_:type:)"
---

# setCredential(_:type:)

Sets an application-provided credential to be used when evaluating authentication.

## Declaration

```swift
func setCredential(_ credential: Data?, type: LACredentialType) -> Bool
```

## Parameters

- `credential`: The credential to be used when evaluating the authentication context. Setting this parameter to nil removes any existing credential of the specified type.
- `type`: The type of the specified credential. For possible values, see doc://com.apple.localauthentication/documentation/LocalAuthentication/LACredentialType.

## Return Value

Return Value true if the credential was set, otherwise false.

## See Also

### Managing credentials

- [isCredentialSet(_:)](localauthentication/lacontext/iscredentialset(_:).md)
- [LACredentialType](localauthentication/lacredentialtype.md)
