Question

I am trying to use SSKeychain in my application to store a user's credentials. I can successfully save the credentails. However, when I try to retrieve the credentials, they are outputted as an NSArray. I want one specific value so I am using valueForKey:NSString which gives me ( acct )

Here is the code I am using

NSArray *accounts = [SSKeychain accountsForService:@"testApp"];
NSString *account = [accounts valueForKey:@"acct"];
NSLog(@"%@", account);

I would like for the output to be acct not (acct).

Was it helpful?

Solution

accountsForService: returns an array of dictionaries, not an array of strings. See the docs: http://cocoadocs.org/docsets/SSKeychain/1.2.2/Classes/SSKeychain.html#//api/name/accountsForService:

You can find the keys you should use to retrieve info from the dictionaries in SSKeyChain.h

OTHER TIPS

Try this:

 NSArray *accounts = [SSKeychain accountsForService:@"testApp"];
 NSString *account = [[accounts valueForKey:@"acct"] objectAtIndex:0];

 NSLog(@"%@", account);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top