title: Initialization of an NSDictionary in Objective C (for iOS)
body: <p>I am relatively new to Objective-C and now I have a problem in my iPhone app that I don't fully understand.
  I try to use a <code>NSMutableDictionary</code>, this does not seem to work as i expect for some reason. When I run the debugger and do <code>po numberToCallerMap</code> to see the dictionary, I get an exception. I have read the documentation for <code>NSMutableDictionary</code> on how to initialize it, but I can not see what I am doing wrong. Help and advice are appreciated. The variable causing me problem is numberToCallerMap, here is the relevant function:</p>
  
  <pre><code>- (void)setData:(NSString*)value{
  [list release];
  list = [[NSMutableArray alloc] init];
  SBJSON *json = [[[SBJSON alloc] init] autorelease];
  NSMutableDictionary* numberToCallerMap;
  CallerInfo* caller;
  NSDictionary* callerInfo;
  
  @try {      
      NSArray *array = (NSArray*)[json objectWithString:value];       
      // reading all the items in the array one by one  
      numberToCallerMap = [NSMutableDictionary dictionary];
  
      for (id *item in array) {  
  
          // if the item is NSDictionary (in this case ... different json file will probably have a different class)  
          NSDictionary *dict2 = (NSDictionary *) item;  
          CallInfo *data = [CallInfo alloc];           
          [data initFromDictionary:dict2];
  
  
          callerInfo = (NSDictionary*)[dict2 valueForKey:@"caller"] ;
  
               //Here, we want the phonenumber to be part of the CallerInfo object instead.
               // It is sent from the server as part of the Call-object
          NSString* number = (NSString*)[dict2 valueForKey:@"phoneNumber"];
          [callerInfo setValue:number forKey:@"phoneNumber"];
  
          caller = (CallerInfo*)[numberToCallerMap valueForKey:number];
          if(caller == nil || [caller isKindOfClass:[NSNull class]]){
              caller = [CallerInfo alloc];
              [caller initFromDictionary:callerInfo];
  
              [numberToCallerMap setValue:caller forKey:number];  
              [list insertObject:caller atIndex:0];
              }
          [caller addRecentCall:data];            
       } 
  }
  @catch (NSException * e) {
      [list release];
      list = [[NSMutableArray alloc] init];
  }
  @finally {
      [numberToCallerMap release];
  }
  }
  </code></pre>