Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I was running into the same exception. The root cause for my problem was I was referencing an key/value pair incorrectly. At runtime, the exception "-[__NSCFConstantString objectAtIndex:]: unrecognized selector sent to instance" was being thrown. This perplexed me for longer than I'd care to admit. But I found the solution to my problem, and hope it can help someone else. The code that was throwing the exception follows along with the corrected code.</p> <p>The erroneous code:</p> <pre><code>- (void)testMyUnitTest { WorldObject *worldObject; NSMutableDictionary *worldCoordinatesAll = [[NSMutableDictionary alloc] init]; WorldCoordinate *localWCoordinate = [[WorldCoordinate alloc] init]; // Populate with a world coordinate object [worldCoordinatesAll setObject:[localWCoordinate updateWithLatitude:X2LOC Longitude:Y2LOC Altitude:0] forKey:@"OBJECT 2"]; for (id objectID in worldCoordinatesAll) { localWCoordinate = (WorldCoordinate *)objectID; localWCoordinate.latitude = LATITUDE_1; // Exception being thrown on this line } } </code></pre> <p>The corrected code:</p> <pre><code>- (void)testMyUnitTest { WorldObject *worldObject; NSMutableDictionary *worldCoordinatesAll = [[NSMutableDictionary alloc] init]; WorldCoordinate *localWCoordinate = [[WorldCoordinate alloc] init]; // Populate with a world coordinate object [worldCoordinatesAll setObject:[localWCoordinate updateWithLatitude:X2LOC Longitude:Y2LOC Altitude:0] forKey:@"OBJECT 2"]; for (id key in worldCoordinatesAll) { id value = [worldCoordinatesAll objectForKey:key]; localWCoordinate = (WorldCoordinate *)value; localWCoordinate.latitude = LATITUDE_1; } } </code></pre> <p>I realize that for some, this might seem like a totally obvious mistake. But for some reason, it took me a week to see it. So I hope it helps someone else save themsleves some time. :-)</p>
 

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