Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Semrush - keyword research tool

Linux Foundation Training and Certification

Teach Your Child To Read

Disclosure: My content contains affiliate links.

32,304 questions

42,479 answers

573 users

How to create key value dictionary in Objective-C

2 Answers

0 votes
#import <Foundation/Foundation.h>

int main (int argc, const char *argv[]) {
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

    NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
                            [NSNumber numberWithInt:6], @"c",
                            [NSNumber numberWithInt:5], @"objective c",
                            [NSNumber numberWithInt:3], @"c++",
                            [NSNumber numberWithInt:9], @"python",
                            [NSNumber numberWithInt:2], @"java", nil];

    NSLog(@"keys:");
    for (id key in dict) {
        NSLog(key);
    }

    NSLog(@"\nvalues:");
    for (id value in [dict objectEnumerator]) {
        NSLog(@"%@", value);
    }

    [pool drain];

    return 0;
}




/*
run:

keys:
python
objective c
java
c
c++

values:
9
5
2
6
3

*/

 



Learn & Practice Python
with the most comprehensive set of 13 hands-on online Python courses
Start now


answered Dec 11, 2022 by avibootz
edited Dec 14, 2022 by avibootz
0 votes
#import <Foundation/Foundation.h>

int main (int argc, const char *argv[]) {
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

    NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
                            [NSNumber numberWithInt:6], @"c",
                            [NSNumber numberWithInt:5], @"objective c",
                            [NSNumber numberWithInt:3], @"c++",
                            [NSNumber numberWithInt:9], @"python",
                            [NSNumber numberWithInt:2], @"java", nil];


    NSEnumerator *enm = [dict keyEnumerator];

    id key;
    NSLog(@"keys:");
    while ((key = [enm nextObject])) {
        NSLog(key);
    }


    enm = [dict objectEnumerator];
    id value;
    NSLog(@"\nvalues:");
    while ((value = [enm nextObject])) {
        NSLog(@"%@", value);
    }

    [pool drain];
    
    return 0;
}




/*
run:

keys:
python
objective c
java
c
c++

values:
9
5
2
6
3

*/

 



Learn & Practice Python
with the most comprehensive set of 13 hands-on online Python courses
Start now


answered Dec 11, 2022 by avibootz
edited Dec 14, 2022 by avibootz

Related questions

1 answer 47 views
1 answer 50 views
...