<!--
{
  "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/URLCredentialStorage/credentials(for:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSURLCredentialStorage(im)credentialsForProtectionSpace:"
  },
  "title" : "credentials(for:)"
}
-->

# credentials(for:)

Returns a dictionary containing the credentials for the specified protection space.

```
func credentials(for space: URLProtectionSpace) -> [String : URLCredential]?
```

## Parameters

`space`

The protection space whose credentials you want to retrieve.

## Return Value

A dictionary containing the credentials for the specified protection space. The dictionary’s keys are user name strings, and each value is the corresponding [`URLCredential`](/documentation/Foundation/URLCredential).

## Discussion

If you override this method, also override [`getCredentials(for:task:completionHandler:)`](/documentation/Foundation/URLCredentialStorage/getCredentials(for:task:completionHandler:)).

---

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)