---
title: "init(forTrust:)"
framework: foundation
role: symbol
role_heading: Initializer
path: "foundation/urlcredential/init(fortrust:)"
---

# init(forTrust:)

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

## Declaration

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

## Parameters

- `trust`: The accepted trust.

## Return Value

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

## Discussion

Discussion Before creating a server trust credential, it is the responsibility of the delegate of an NSURLConnection instance or an NSURLDownload instance to evaluate the trust. Do this by calling SecTrustEvaluate(_:_:), passing it the trust obtained from the serverTrust method of the server’s URLProtectionSpace instance. If the trust is invalid, the authentication challenge should be cancelled with cancel(_:).

## See Also

### Creating a credential

- [init(identity:certificates:persistence:)](foundation/urlcredential/init(identity:certificates:persistence:).md)
- [init(trust:)](foundation/urlcredential/init(trust:).md)
- [init(user:password:persistence:)](foundation/urlcredential/init(user:password:persistence:).md)
- [URLCredential.Persistence](foundation/urlcredential/persistence-swift.enum.md)
