Search code examples
ioskeychainkeychainitemwrapper

fetching all items in keychain in one shot?


I started reading this apple sample for keychain and understood that they are fetching all the values for this keychain item associated to type kSecAttrGeneric. Then when someone tries to search for a key they do it form the cached value, is this the right approach, i somehow feel that this way of prefetching is incorrect.

Can you please let me know what could be the reason for prefetching all the data from keychain rather than taking accessing it directly from keychain based on the need.

https://developer.apple.com/library/ios/samplecode/GenericKeychain/Introduction/Intro.html


Solution

  • I believe you're slightly misreading that example. In GenericKeychain, they're not fetching "all items." They're fetching just one item and its one value. A keychain item is made up of properties, which are semi-public, and a "value" which is protected. Reading out of the keychain is fantastically expensive (much, much slower than reading a file off of disk; it's really shockingly slow). So the example is avoiding re-reading it when not needed. But it's not reading the entire keychain; just the one item that stores its data.