Firemarble Firemarble - 6 months ago 13
Objective-C Question

NSArrayM unrecognized selector error

I need some help understanding why I am getting an

unrecognized selector error


I have a
NSMutableDictionary


@interface CallDetailViewController () {
NSMutableDictionary * thisDictionary;
}

@end


That gets populated from the MasterTabController

- (void) some method {
thisDictionary = [[(MasterTabController *)self.tabBarController detailDictionary] mutableCopy];

NSLog(@"Check dictinoary: %@", [thisDictionary description]);

}


Outputting a description shows the data is there


Check dictinoary: (
{

DATEIN = "2015-12-11 13:33:41";

"ETA" = "2015-12-14 13:54:16";

RecordKey = 2961;

Destination = "Some address";
Location = "Some location";
} )


But when I try to access an object in it:

NSLog(@"Destination: %@", [thisDictionary objectForKey:@"Destination"]);


I get the following error.


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


The array is populated from a JSON value that returns an array of records called Record. After the JSON is returned, I pull out just section that contains the record.

NSDictionary * dictTowx = [NSDictionary dictionaryWithDictionary:[dictJSON objectForKey:@"ThisResponse"]];
NSDictionary * dictData = [NSDictionary dictionaryWithDictionary:[dictTowx objectForKey:@"Data"]];
NSArray * arrRecordSet = [dictData objectForKey:@"Recordset"];
NSDictionary * dicRecord= [arrRecordSet objectAtIndex:0];
self.detailDictionary = [dicRecord objectForKey:@"Record"];


The RAW JSON:

{
ThisResponse = {
Data = {
Recordset = (
{
Record = (
{
DATEIN = "2015-12-11 13:33:41";
"ETA" = "2015-12-14 13:54:16";
RecordKey = 2961;
Destination = "Some address";
Location = "Some location";
}
);
}
);
};
};
}


What am I doing wrong?

Answer

Please try to assign like this

self.detailDictionary   = [[dicRecord objectForKey:@"Record"] objectAtIndex:0];

and then access like this

 NSLog(@"Destination: %@", [thisDictionary objectForKey:@"Destination"]);

Enjoy programming.