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

# SecKeychainSearchCopyNext

Finds the next keychain item matching the given search criteria.

```
OSStatus SecKeychainSearchCopyNext(SecKeychainSearchRef searchRef, SecKeychainItemRef*itemRef);
```

## Parameters

`searchRef`

A reference to the current search criteria. The search object is created in the [`SecKeychainSearchCreateFromAttributes`](/documentation/Security/SecKeychainSearchCreateFromAttributes) function and must be released by calling the `CFRelease` function when you are done with it.

`itemRef`

On return, a pointer to a keychain item object of the next matching keychain item, if any. In Objective-C, call the <doc://com.apple.documentation/documentation/CoreFoundation/CFRelease> function to release this object when you are finished using it.

## Return Value

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

## Discussion

> Important:
> This function is deprecated.
> The common security services manager module is no longer used.

Each item stored in the keychain contains data (such as a certificate), which is indexed by the item’s attributes. Use the [`SecKeychainSearchCreateFromAttributes`](/documentation/Security/SecKeychainSearchCreateFromAttributes) function to specify attributes to search for. If the `SecKeychainSearchCopyNext` function finds a match, you can use the [`SecKeychainItemCopyAttributesAndData(_:_:_:_:_:_:)`](/documentation/Security/SecKeychainItemCopyAttributesAndData(_:_:_:_:_:_:)) function to retrieve the item’s data.

A [`SecKeychainItem`](/documentation/Security/SecKeychainItem) object for a certificate that is stored in a keychain can be safely cast to a [`SecCertificate`](/documentation/Security/SecCertificate) for use with the Certificate, Key, and Trust API.

To find and obtain data from a password keychain item, use the [`SecKeychainFindInternetPassword(_:_:_:_:_:_:_:_:_:_:_:_:_:_:_:)`](/documentation/Security/SecKeychainFindInternetPassword(_:_:_:_:_:_:_:_:_:_:_:_:_:_:_:)) or [`SecKeychainFindGenericPassword(_:_:_:_:_:_:_:_:)`](/documentation/Security/SecKeychainFindGenericPassword(_:_:_:_:_:_:_:_:)) function.

---

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)