0
votes

I have an NSMutableDictionary called "myScheduleFullDictionary" set up like this:

  KEY             VALUE
"Day 1"         An NSMutableArray of NSMutableDictionaries
"Day 2"         An NSMutableArray of NSMutableDictionaries
"Day 3"         An NSMutableArray of NSMutableDictionaries

etc.

I'm trying to parse it - basically grab one of the MutableArrays contained as the Value of one of the Keys. Here is my code:

// First I make a mutableCopy of the entire Dictionary:
NSMutableDictionary *copyOfMyScheduleDictionary = [myScheduleFullDictionary mutableCopy];

// Next I grab & sort all the KEYS from it:
NSArray *dayKeysArray = [[copyOfMyScheduleDictionary allKeys] sortedArrayUsingSelector:@selector(compare:)];

// I set up an NSMutableArray to hold the MutableArray I want to grab: 
NSMutableArray *sessionsInThatDayArray = [[NSMutableArray alloc] init];

// Then I iterate through the KEYs and compare each to the one I'm searching for:
for (int i = 0; i < [dayKeysArray count]; i++) {

    NSString *currentDayKey = [dayKeysArray objectAtIndex:i];        
    if ([currentDayKey isEqualToString: targetDayString]) {
        NSLog(@"FOUND MATCH!!!");

        // I log out the NSMutableArray I found - which works perfectly:
        NSLog(@"found array is: %@", [copyOfMyScheduleDictionary objectForKey:currentDayKey]);

        // But when I try to actually grab it, everything crashes:
        sessionsInThatDayArray = [copyOfMyScheduleDictionary objectForKey:currentDayKey];
        break;
    }
}

The error I get is:

-[__NSDictionaryM name]: unrecognized selector sent to instance 0x1c5fb2d0

Not sure why its pointing out "name" as the "unrecognized selector." "name" is an NSString property of a "Session" class I declared and am working with - could that be related somehow?

Any insights?

EDIT:

Here is my "SessionObject" class definition:

@interface SessionObject : NSObject


@property (nonatomic, strong) NSString *name;
@property (nonatomic, strong) NSString *speaker;
@property (nonatomic, strong) NSString *location;
@property (nonatomic, strong) NSDate *startTime, *endTime;
@property (nonatomic, strong) NSString *notes;
@property (nonatomic, strong) NSString *dayOfConference;


@end
2
Where is name been used? - yeesterbunny
Are you sure that's the line causing the error? Have you added an exception breakpoint? It doesn't make sense that the log should work, but not the next line. - rdelmar
how do I add an exception breakpoint? You mean a try-catch block? - sirab333
In Xcode's breakpoints sidebar, at the bottom, there's a plus. You can add exception breakpoints via that. They're breakpoint that trigger as soon as an exception is thrown (not at all the same thing as @catch). - Catfish_Man
WAIT. I think you're right. I think its crashing after all that. Hang on... - sirab333

2 Answers

1
votes
-[__NSDictionaryM name]: unrecognized selector sent to instance 0x1c5fb2d0

This means that you are trying to call name on an NSMutableDictionary where as you should have called it on an object of class SessionObject. Check the line where you are calling something like myObject.name or [myObject name] and see if myObject is of type SessionObject and not NSMutableDictionary.

Here __NSDictionaryM denotes the NSMutableDictionary type.

0
votes

I'm not sure where your bug comes from - but what are you doing there? Why don't you just write

sessionsInThatDayArray = [myScheduleFullDictionary objectForKey:targetDayString];

??? That's what NSDictionary is there for - you don't search for things by hand, you just call the method to look up the key. Instead you copied the dictionary, you extracted all the keys, you sorted the keys, you iterated through them one by one until you found it - and then you called objectForKey!!!

Apart from that, in the debugger set a breakpoint on all Objective-C exceptions. It will stop when the offending code is called, so no need to search for a needle in the haystack.