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

# init(trust:)

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

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

## Parameters

`trust`

The accepted trust.

## Return Value

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

## Discussion

Before your implementation of [`urlSession(_:task:didReceive:completionHandler:)`](/documentation/Foundation/URLSessionTaskDelegate/urlSession(_:task:didReceive:completionHandler:)) uses this initializer to create a server trust credential, you are responsible for evaluating the received <doc://com.apple.documentation/documentation/Security/SecTrust> instance. You get this [`serverTrust`](/documentation/Foundation/URLProtectionSpace/serverTrust) from the [`protectionSpace`](/documentation/Foundation/URLAuthenticationChallenge/protectionSpace) of the [`URLAuthenticationChallenge`](/documentation/Foundation/URLAuthenticationChallenge) parameter that is passed to your delegate method. Pass the trust instance to <doc://com.apple.documentation/documentation/Security/SecTrustEvaluate(_:_:)> to evaluate it. If this call indicates the trust is invalid, you should cancel the challenge by passing the [`URLSession.AuthChallengeDisposition.cancelAuthenticationChallenge`](/documentation/Foundation/URLSession/AuthChallengeDisposition/cancelAuthenticationChallenge) disposition to the completion handler.

---

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)