I have a NSDictionary with two arrays like this
questionAndAnswer= [NSDictionary dictionaryWithObject:answerList forKey:questionList];
there are two answerList objects for particular question(key). that part is OK (dictionary is populate correctly)
I want to insert answers to a new array called chckList with respect to selected question. I tried like this
NSString *selectedQuestion=[questionList objectAtIndex:indexPath.row];
[self.checkList insertObject:[questionAndAnswer objectForKey:selectedQuestion] atIndex:0];
But it fires an exception, what’s wrong in my code?
You should actually do (note the plurals in the method name):
What you posted used one array as key for another. The above uses the items in one array as keys for the other array. Big difference.
But the error message you get “sounds” very much like an uninitialized or already dealloced and “re-used” variable. So:
questionAndAnsweryou query is the same as the one you created;dictionaryWithObjects:forKeys:convenience method returns an auto-released object, and you should take care of retaining it before the autorelease pool can release it. Use a@property (retain)and@synthesizeit to store it.