<!--
{
  "availability" : [
    "iOS: 3.0.0 -",
    "iPadOS: 3.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.6.0 -",
    "swift: -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/URLCredential/init(forTrust:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSURLCredential(cm)credentialForTrust:::SYNTHESIZED::c:objc(cs)NSURLCredential"
  },
  "title" : "init(forTrust:)"
}
-->

# init(forTrust:)

Creates a URL credential instance for server trust authentication with a given accepted trust.

```
init(forTrust trust: SecTrust)
```

## Parameters

`trust`

The accepted trust.

## Return Value

A new URL credential object, containing the accepted server trust.

## Discussion

Before creating a server trust credential, it is the responsibility of the delegate of an [`NSURLConnection`](/documentation/Foundation/NSURLConnection) instance or an [`NSURLDownload`](/documentation/Foundation/NSURLDownload) instance to evaluate the trust. Do this by calling <doc://com.apple.documentation/documentation/Security/SecTrustEvaluate(_:_:)>, passing it the trust obtained from the `serverTrust` method of the server’s [`URLProtectionSpace`](/documentation/Foundation/URLProtectionSpace) instance. If the trust is invalid, the authentication challenge should be cancelled with [`cancel(_:)`](/documentation/Foundation/URLAuthenticationChallengeSender/cancel(_:)).

---

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)