2 Replies
      Latest reply on Jan 22, 2018 7:31 PM by rowlands
      rowlands Level 1 Level 1 (0 points)

        Can kSecUseKeychain be used with SecItemCopyMatching?


        I'm trying to find a way to display to the user on which KeyChain some items are.

        • Re: SecItemCopyMatching kSecUseKeychain
          eskimo Apple Staff Apple Staff (13,875 points)

          Can kSecUseKeychain be used with SecItemCopyMatching?

          No.  kSecUseKeychain is only relevant when adding items.  The doc comments in the header are pretty clear about this:

          You use this key to specify a value of type SecKeychainRef to which SecItemAdd will add the provided item(s).

          The droid you’re looking for is kSecMatchSearchList.  It’s doc comments say:

          If provided, the search will be limited to the keychains contained in this list.

          Share and Enjoy

          Quinn “The Eskimo!”
          Apple Developer Relations, Developer Technical Support, Core OS/Hardware
          let myEmail = "eskimo" + "1" + "@apple.com"

            • Re: SecItemCopyMatching kSecUseKeychain
              rowlands Level 1 Level 1 (0 points)

              Thanks man, as usual you're always incredibly helpful.


              I noticed the comment in the header file, but when I double checked online, (by navigating through the SecitemCopyMatching) it showed the key, so I completlated if it was a documentation mistmatch and tried it.


              I really appreciate the pointer, as the only other solution I'd found was using SecKeychainSetSearchList and while it worked, there was one time when it didn't and it erased my Keychain, thankfully I had a backup. However it made me too nervous to include it a customer facing application.