Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I read just the key from plist?

Can I read just the key from plist without its value, also if I know the value can I read the key ?

like image 883
Bobj-C Avatar asked Jun 04 '11 11:06

Bobj-C


2 Answers

Reading .plist:

NSString *path = [[NSBundle mainBundle] pathForResource:@"myPlist" ofType:@"plist"];    
NSMutableDictionary *myDictionary = [[NSMutableDictionary alloc] initWithContentsOfFile:path];

Getting all keys and all values:

NSArray* allmyKeys = [myDictionary  allKeys];
NSArray* allmyValues= [myDictionary  allValues];

Getting all keys for an values object:

NSArray* allmyKeys = [myDictionary  allKeysForObject:myValueObject];
like image 136
Jhaliya - Praveen Sharma Avatar answered Oct 12 '22 21:10

Jhaliya - Praveen Sharma


As an alternative, you can use allKeysForObject: method which returns,

A new array containing the keys corresponding to all occurrences of anObject in the dictionary. If no object matching anObject is found, returns an empty array.

From that array you can get the key by invoking the objectAtIndex: method.

like image 27
EmptyStack Avatar answered Oct 12 '22 21:10

EmptyStack