---
title: "setDefaultCredential(_:for:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/urlcredentialstorage/setdefaultcredential(_:for:)"
---

# setDefaultCredential(_:for:)

Sets the default credential for a specified protection space.

## Declaration

```swift
func setDefaultCredential(_ credential: URLCredential, for space: URLProtectionSpace)
```

## Parameters

- `credential`: The URL credential to set as the default for space. If the receiver does not contain credential in the specified protection space it will be added.
- `space`: The protection space whose default credential is being set.

## Discussion

Discussion If you override this method, also override setDefaultCredential(_:for:task:).

## See Also

### Getting and setting default credentials

- [defaultCredential(for:)](foundation/urlcredentialstorage/defaultcredential(for:).md)
- [getDefaultCredential(for:task:completionHandler:)](foundation/urlcredentialstorage/getdefaultcredential(for:task:completionhandler:).md)
- [setDefaultCredential(_:for:task:)](foundation/urlcredentialstorage/setdefaultcredential(_:for:task:).md)
