Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat would cause objectForKey: to return null with a valid string in place?
    primarykey
    data
    text
    <p>I am having an issue with <code>NSDictionary</code> returning <code>null</code> for an <code>NSString</code> even though the string is in the dictionary. Here is the code:</p> <pre><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); } </code></pre> <p>And I get the following log statements:</p> <pre><code>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) </code></pre> <p>As you can see, the string is in the dictionary under the key <code>newSource</code>, yet when I call <code>objectForKey:</code>, I get <code>null</code>. I have even tried the fallback option of cleaning the project.</p> <p>Has anyone ever run into this, or have I just forgotten something really basic?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload