-5

How to store the given below into NSDictionary

{

"Test":"Example"

}

  • NSmutableDictionary *info = [NsmutableDictionary allo]init]; [info setObject:passValue forKey:passKeyValue]; // like [info setObject:@"Example" forKey:@"Test"]; – HariKrishnan.P Jun 24 '16 at 06:41
  • 1
    `NSDictionary *dict = @{@"Test":@"Example"};` ? – vadian Jun 24 '16 at 06:41
  • Possible duplicate of [How to insert a new key with value in dictionary](http://stackoverflow.com/questions/4285875/how-to-insert-a-new-key-with-value-in-dictionary) – 7vikram7 Jun 24 '16 at 06:55

2 Answers2

0

You can add value for key by using this

NSDictionary *dictionary=[NSDictionary dictionaryWithObjectsAndKeys:@"Test",@"Example", nil];
Ajharudeen khan
  • 246
  • 2
  • 10
0

You can add value for key by using 'initWithObjects:(objects) forKeys:'

NSDictionary* dictionary = [[NSDictionary alloc] initWithObjects:@[@"Example",@"Example2"] forKeys:@[@"Test",@"Test2"]];
NSLog(@"%@",dictionary);
//{
//    Test = Example;
//    Test2 = Example2;
//}

Or you can use NSMutableDictionary :

 NSMutableDictionary *mutableDictionary = [[NSMutableDictionary alloc] init];
[mutableDictionary setObject:@"Example" forKey:@"Test"];
[mutableDictionary setObject:@"Example2" forKey:@"Test2"];
NSLog(@"%@",mutableDictionary);
//{
//    Test = Example;
//    Test2 = Example2;
//}

Same output for these. Also you should take a look