user1227928
user1227928

Reputation: 829

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 ?

Upvotes: 3

Views: 2298

Answers (1)

Nikolai Ruhe
Nikolai Ruhe

Reputation: 81856

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.

Upvotes: 6

Related Questions