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

# SecKeychainLock(_:)

Locks a keychain.

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

## Parameters

`keychain`

A reference to the keychain to lock. Pass `NULL` to lock the default keychain.

## 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 specified keychain could not be found. The result code [`errSecInvalidKeychain`](/documentation/Security/errSecInvalidKeychain) indicates that the specified keychain is invalid.

## Discussion

Your application should not call this function unless you are responding to a user’s request to lock a keychain. In general, you should leave the keychain unlocked so that the user does not have to unlock it again in another application.

---

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)