Objective-C: How to create a dictionary?

  • A key is always unique, and it will not have any duplicates. As, it is used as an identifier to retrieve a value.
  • A value need not be unique, and it can be a duplicate. But its associated key is always unique.
#import <Foundation/Foundation.h>

int main (int argc, const char * argv[])
{
// Empty dictionary stored in dict
NSDictionary *dict = [NSDictionary dictionary];
NSLog(@"value of dict is %@",dict);

return 0;
}
#import <Foundation/Foundation.h>

int main (int argc, const char * argv[])
{
NSDictionary *dict = [[NSDictionary alloc] initWithObjectsAndKeys: @"value", @"key", nil];
NSLog(@"value of dict is %@",dict);

return 0;
}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Akarsh SEGGEMU

Akarsh SEGGEMU

Software Engineer (Android, iOS, Unity) | M.Sc. Computer Science — Technische Universitaet Berlin | Mobile Advertising, Attribution, Monetisation, UA & Analytic