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

# SecKeychainSetDefault(_:)

Sets the default keychain.

```
func SecKeychainSetDefault(_ keychain: SecKeychain?) -> OSStatus
```

## Parameters

`keychain`

A reference to the keychain you wish to make the default.

## Return Value

A result code. See [Security Framework Result Codes](/documentation/Security/security-framework-result-codes). The result code [`errSecNoSuchKeychain`](/documentation/Security/errSecNoSuchKeychain) indicates that the specified keychain could not be found. The result code [`errSecInvalidKeychain`](/documentation/Security/errSecInvalidKeychain) indicates that the specified keychain is invalid.

## Discussion

In most cases, your application should not need to set the default keychain, because this is a choice normally made by the user. You may call this function to change where a password or other keychain items are added, but since this is a user choice, you should set the default keychain back to the user specified keychain when you are done.

---

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)