What would cause objectForKey: to return null with a valid string in place?

Posted by theMikeSwan on Stack Overflow See other posts from Stack Overflow or by theMikeSwan
Published on 2010-04-18T04:15:43Z Indexed on 2010/04/18 4:23 UTC
Read the original article Hit count: 243

Filed under:

I am having an issue with NSDictionary returning null for an NSString even though the string in in the dictionary. Here is the code:

- (void)sourceDidChange:(NSNotification *)aNote {
NSDictionary *aDict = [aNote userInfo];
DLog(@"%@", aDict);
NSString *newSourceString = [aDict objectForKey:@"newSource"];
DLog(@"%@", newSourceString);
newSourceString = [newSourceString stringByReplacingOccurrencesOfString:@" " withString:@""];
DLog(@"%@", newSourceString);
NSString *inspectorString = [newSourceString stringByAppendingString:@"InspectorController"];
DLog(@"%@", inspectorString);
newSourceString = [newSourceString stringByAppendingString:@"ViewController"];
DLog(@"%@", newSourceString);             }

And I get the following log statements:

2010-04-17 23:50:13.913 CoreDataUISandbox[13417:a0f] -[RightViewController sourceDidChange:]     newSource = "Second View"; 
2010-04-17 23:50:13.914 CoreDataUISandbox[13417:a0f] -[RightViewController sourceDidChange:] (null)
2010-04-17 23:50:13.916 CoreDataUISandbox[13417:a0f] -[RightViewController sourceDidChange:] (null)
2010-04-17 23:50:13.917 CoreDataUISandbox[13417:a0f] -[RightViewController sourceDidChange:] (null)
2010-04-17 23:50:13.917 CoreDataUISandbox[13417:a0f] -[RightViewController sourceDidChange:] (null)

As you can see the string is in the dictionary under the key newSource, yet when I call objectForKey: I get null. I have even tried the fallback option of cleaning the project. Has anyone ever run into this, or have I just forgotten something really basic?

© Stack Overflow or respective owner

Related posts about cocoa