gdm
gdm

Reputation: 7978

NSDictionary misteries

I used many time:

NSMutableDictionary* temp   = [[NSMutableDictionary alloc] init];
[temp setDictionary:[[NSDictionary alloc] initWithObjectsAndKeys:
                                            [currentEvent objectForKey:@"title"],@"titolo",
                                            [currentEvent objectForKey:@"testo"],@"testo",
                                            [currentEvent objectForKey:@"start"],@"date",
                                            [NSString stringWithFormat:@"%d",lastId],@"att_id",
                                            [currentEvent objectForKey:@"pr_id"],@"pr_id",
                                            nil]];
            NSLog(@"%@",temp);

but this time, the log prints out:

2013-11-22 14:39:08.152 MyApp[93198:70b] {
    titolo = asdasda;
}

Why it is just getting one object? In the debugger I can see that currentEvent has all kesy/objest set...

Upvotes: 0

Views: 66

Answers (1)

Thomas Keuleers
Thomas Keuleers

Reputation: 6115

The method call

initWithObjectsAndKeys

is nil terminated. If [currentEvent objectForKey:@"testo"] is nil, the dictionary will ignore all the objects you passed after it.

Upvotes: 5

Related Questions