Creating an Array with the Keys of a Dictionary

Asked

Viewed 154 times

1

I have a Dictionary as image below and would like to play Dictionary medicines keys names for an array, as I can perform so function

inserir a descrição da imagem aqui

  • Why medicamentos is a dictionary instead of a vector?

2 answers

3


Nsdictionary has the method - (NSArray *)allKeys which returns an array containing all the keys of the dictionary

  • 2

    It is good to remember that the order of the keys in the vector returned by -[NSDictionary allKeys] is undefined. In particular, there is no guarantee that the order is equal in separate executions even if the dictionary contains the same key-value pairs.

0

NSString * path= [[NSBundle mainBundle]pathForResource:@"Medicamentos" ofType:@"plist"];

    NSDictionary * dadosArquivo =[NSDictionary dictionaryWithContentsOfFile:path];

    NSArray * medicamentos =[dadosArquivo objectForKey:@"medicamentos"]; //

   NSLog(@"%@", medicamentos);

I guess that’s it.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.