1

I am trying to add an object to an NSMutableDictionary using the setObject:forKey: function, but for whatever reason, when I run my app in the iPhone simulator and try to perform the action, the code stops at the line were I am trying to add the object to the dictionary. The line where the program gets stuck is as follows:

[_dict setObject:_tf.text forKey:[NSString stringWithFormat:@"keywords_%i", [_keywordsArray count]]];

Where '_dict' is an NSMutableDictionary object, '_tf' is a UITextField, and '_keywordsArray' is an NSMutableArray.

Overall, I am using the objects (aka keys) from my dictionary to populate an NSMutableArray, which is used to fill a UIPickerView. Initially, I load the dictionary from a .plist file, and I can tell the NSMutableDictionary and the NSMutableArray are both getting populated/filled correctly, and that the UIPickerView is working fine, the only part that isn't working is adding objects to the NSMutableDictionary (when the user presses a button in the UI). Also, I did get an error once that said that the NSMutableArray had a count of 0 (zero), when clearly it didn't.

Any help/suggestions would be greatly appreciated!

prashant
  • 1,920
  • 14
  • 26
iphonedev7
  • 295
  • 1
  • 7
  • 17
  • 3
    What error message are you getting? – Julian Jul 10 '12 at 18:34
  • It would also be good to have a debug `watch`, where we can really see that what you claim to be NSMutableArray is one and its not NSArray. It recently happened to me that I had accepted an NSArray returned by sortArrayWithSelector... in a variable defined as NSMutableArray. It did not give problems in that part of the code, but when I tried to removeObject from this array, the app crashed. And I found out that its the sort function which is returning an NSArray. The error only shows up later. – Ozair Kafray Jul 10 '12 at 18:37
  • Use the debugger and breakpoints to step by step the code. It might be that you are pointing to the incorrect object, the NSMutableArray has a weak retain tag OR that you didn't alloc init something – Im_Lp Jul 10 '12 at 18:44
  • The error I'm getting is 'Thread 1: breakpoint 1.1'. Also, @OzairKafray: I checked for what you suggested, and I don't believe that's the error. I can post all of the code if that helps at all. – iphonedev7 Jul 10 '12 at 18:45
  • possible duplicate of [getting breakpoint retrieving addressbook data](http://stackoverflow.com/questions/10406572/getting-breakpoint-retrieving-addressbook-data) – jscs Jul 10 '12 at 19:52
  • Breakpoints aren't errors. They're something you control. – jscs Jul 10 '12 at 19:53

0 Answers0