Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

tranvutuan

macrumors member
Original poster
Dec 19, 2011
74
0
What I am having so far right now is

Code:
    NSArray *keys = [NSArray arrayWithObjects:@"firstName",@"lastName",@"phoneNumber",@"email",@"password",nil];

    NSArray *objects = [NSArray arrayWithObjects:@"nil",@"nil",@"nil",@"nil",@"abc",nil];

    dictionary = [NSDictionary dictionaryWithObject:objects forKey:keys];

    NSLog(@"pass is %@",[keys objectAtIndex:4]);

    NSLog(@"value of pass is%@",[dictionary objectForKey:@"password"]);

However, What I got from the debugger is

Code:
    pass is password

    value of pass is (null)

Can anyone explain why the value is null.It should be abc,shouldn't it.
 

OverByThere

macrumors newbie
Nov 24, 2011
28
0
Rugby, UK
I think you want dictionaryWithObjects rather dictionaryWithObject, here is the code that (for me) works:
Code:
NSArray *keys = [NSArray arrayWithObjects:@"firstName",@"lastName",@"phoneNumber",@"email",@"password",nil];
    
    NSArray *objects = [NSArray arrayWithObjects:@"nil",@"nil",@"nil",@"nil",@"abc",nil];
    
    NSDictionary *dictionary = [[NSDictionary alloc] init];
    
    dictionary = [NSDictionary dictionaryWithObjects:objects forKeys:keys];
    
    NSLog(@"pass is %@",[keys objectAtIndex:4]);
    
    NSLog(@"value of pass is%@",[dictionary objectForKey:@"password"]);

Note I have initialised the Array in this version just so I can test it, you can remove that line.
 

tranvutuan

macrumors member
Original poster
Dec 19, 2011
74
0
I think you want dictionaryWithObjects rather dictionaryWithObject, here is the code that (for me) works:
Code:
NSArray *keys = [NSArray arrayWithObjects:@"firstName",@"lastName",@"phoneNumber",@"email",@"password",nil];
    
    NSArray *objects = [NSArray arrayWithObjects:@"nil",@"nil",@"nil",@"nil",@"abc",nil];
    
    NSDictionary *dictionary = [[NSDictionary alloc] init];
    
    dictionary = [NSDictionary dictionaryWithObjects:objects forKeys:keys];
    
    NSLog(@"pass is %@",[keys objectAtIndex:4]);
    
    NSLog(@"value of pass is%@",[dictionary objectForKey:@"password"]);

Note I have initialised the Array in this version just so I can test it, you can remove that line.
thanks for your help, i just tried and it worked
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.