简体   繁体   中英

iOS App Exception - Terminating app due to uncaught exception 'NSInvalidArgumentException'

I am getting the following exception, which is terminating the app.

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM objectForKey:]: unrecognized selector sent to instance 0x7abe4f90'

Following is the code:

- (NSMutableData*)dataForConnection:(URLConnection*)connection {       
NSMutableData *data = [receivedData objectForKey:connection.tagKey]; // Exception Here
return data;
}

Could anyone please suggest how to fix it? Thank you in advance!

[__NSArrayM objectForKey:]

NSArray have not method called objectForKey:

Your object receivedData is NSArray class , change to NSDictionary .

Problem is due to not allocating receivedData properly, since you have declared it as instance variable, so you should make it using the property declaration like this:

@property(nonatomic, strong) NSMutableDictionary *receivedData;

This will ensure that receivedData does not get released and reference this using self.receivedData in your code. Maybe this is helpful

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM