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

# defaultCredential(for:)

Returns the default credential for the specified protection space.

```
func defaultCredential(for space: URLProtectionSpace) -> URLCredential?
```

## Parameters

`space`

The URL protection space of interest.

## Return Value

The default credential for `space` or `nil` if no default has been set.

## Discussion

If you override this method, also override [`getDefaultCredential(for:task:completionHandler:)`](/documentation/Foundation/URLCredentialStorage/getDefaultCredential(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)