views:

147

answers:

1

Hello all,

I've got a chunk of code that's passing an NSMutableDictionary (amongst other things) to a method in another class:

[self.shuttle makeAPICallAndReturnResultsUsingMode:@"login" module:@"login" query:credentials];

The NSMutableArray credentials is previously defined like this:

NSMutableDictionary *credentials = [[NSMutableDictionary alloc] init];
[credentials setObject:username forKey:@"username"];
[credentials setObject:password forKey:@"password"];

The method that receives it looks like this:

-(id)makeAPICallAndReturnResultsUsingMode:(NSString *)mode module:(NSString *)module query:(NSMutableDictionary *)query

The code works fine up until this point within the above method:

 [query setObject:self.sessionID forKey:@"session_id"];

At this point, the application terminates -- the console informs me of this exception:

* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[NSCFDictionary setObject:forKey:]: method sent to an uninitialized mutable dictionary object'

This leads me to believe that I must initialize NSMutableDictionary in some way in my new method before I can access it, but I have no idea how. Any advice?

A: 

You don't have to re-initialize the object in any way in the new method. You say the credentials array "is previously defined", but where is it defined? In the same method that calls makeAPICallAndReturnResultsUsingMode... ? Did you do anything with queryin the makeAPI... method before the line that throws the exception?

Felixyz
It is previously defined just prior to the self.shuttle call that passes it to makeAPICallAndReturnResultsUsingMode -- per the OP I do add two values to the NSMutableDictionary, but that's it. And nope, nothing is done to it, the method literally looks like this: -(id)makeAPICallAndReturnResultsUsingMode:(NSString *)mode module:(NSString *)module query:(NSMutableDictionary *)query { [query setObject:self.sessionID forKey:@"session_id"];
roswell