Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to store array of string in Keychain?

i have followed "GenericKeychain" sample app from apple & already able to write a string into keychain & also able to read it from keychain.

But i am wondering how can i store an array of string inside keychain, Is it possible ? How ?

like image 707
user1227928 Avatar asked Dec 07 '25 13:12

user1227928


1 Answers

You can only store objects of type CFDataRef (which is toll-free bridged to NSData) in a keychain.

To store an array of strings you would typically use property list serialization:

NSArray *myArray = @[@"my", @"strings"];
NSData *data = [NSPropertyListSerialization dataWithPropertyList:myArray format: NSPropertyListBinaryFormat_v1_0 options:0 error:NULL];

Now you can put data into the keychain.

like image 161
Nikolai Ruhe Avatar answered Dec 09 '25 02:12

Nikolai Ruhe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!