Saturday, 23 April 2011

getting the value of key in dictionary incorrectly


what having far right 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 %@",[keys objectatindex:4]);        nslog(@"value of pass is%@",[dictionary objectforkey:@"password"]);
however, got debugger is

code:
    pass password        value of pass (null)
can explain why value null.it should abc,shouldn't it.
 

i think want dictionarywithobjects rather dictionarywithobject, here code (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 %@",[keys objectatindex:4]);          nslog(@"value of pass is%@",[dictionary objectforkey:@"password"]);
note have initialised array in version can test it, can remove line.
 


Forums iPhone, iPad, and iPod Touch iOS Programming


  • iPhone
  • Mac OS & System Software
  • iPad
  • Apple Watch
  • Notebooks
  • iTunes
  • Apple ID
  • iCloud
  • Desktop Computers
  • Apple Music
  • Professional Applications
  • iPod
  • iWork
  • Apple TV
  • iLife
  • Wireless

No comments:

Post a Comment