<!--
{
  "availability" : [
    "macOS: 10.7.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Security",
  "identifier" : "/documentation/Security/SecIdentitySetPreferred(_:_:_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "Security"
    ],
    "preciseIdentifier" : "c:@F@SecIdentitySetPreferred"
  },
  "title" : "SecIdentitySetPreferred(_:_:_:)"
}
-->

# SecIdentitySetPreferred(_:_:_:)

Sets the identity that should be preferred for the specified name and key use.

```
func SecIdentitySetPreferred(_ identity: SecIdentity?, _ name: CFString, _ keyUsage: CFArray?) -> OSStatus
```

## Parameters

`identity`

The identity to set as preferred for the specified name and key usage.

`name`

A string containing an email address (RFC 822) or other name for which a preferred certificate is requested.

`keyUsage`

An array containing a list of usage attributes ([`kSecAttrCanEncrypt`](/documentation/Security/kSecAttrCanEncrypt), for example), or `NULL` if you want this identity to be preferred for any usage. See Attribute Item Keys for a complete list of possible usage attributes.

## Return Value

A result code. See [Security Framework Result Codes](/documentation/Security/security-framework-result-codes).

## Discussion

---

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)