Note that there are some explanatory texts on larger screens.

plurals
  1. POCollecting data from NSArrays, Featuring Inexplicable Behaviour
    text
    copied!<p>I have an array of objects in my Cocoa project. If the objects have an attribute that matches the passed-in value, then the object should be saved to a new array, which is the return value of the method. This seems really straight-forward, but I'm seeing some strange behaviour. Here's the method:</p> <pre><code>- (NSMutableArray*)tagAttributeRectsForID:(NSString*)nodeID { NSMutableArray * resultArray = [NSMutableArray array]; for (NSDictionary * line in self.lineInfoForTap) { NSMutableArray * glyphRects = [line valueForKey:@"GlyphRects"]; for (NSDictionary * rectDict in glyphRects) { if ([rectDict valueForKey:nodeID]) { CGRect thisRect = CGRectFromString([rectDict valueForKey:nodeID]); if (thisRect.size.width &gt; 0) { [resultArray addObject:NSStringFromCGRect(thisRect)]; } } } glyphRects = nil; } return resultArray; } </code></pre> <p>What happens is, depending on the number of line objects that result in a set of matches, that's how many times I get the complete set of results in the returning array. In other words, I would expect a specimen result to look like this:</p> <pre><code>2013-04-16 19:38:37.665 Vorpal[18523:c07] ( "{{0, 486.5}, {38.44, 13.5}}", "{{100, 486.5}, {27.12, 13.5}}", "{{140, 483.34}, {86.54, 16.66}}", "{{0, 508.86}, {58.62, 14.14}}" ) </code></pre> <p>But instead I get this:</p> <pre><code>2013-04-16 19:38:37.665 Vorpal[18523:c07] ( "{{0, 486.5}, {38.44, 13.5}}", "{{100, 486.5}, {27.12, 13.5}}", "{{140, 483.34}, {86.54, 16.66}}", "{{0, 508.86}, {58.62, 14.14}}", "{{0, 486.5}, {38.44, 13.5}}", "{{100, 486.5}, {27.12, 13.5}}", "{{140, 483.34}, {86.54, 16.66}}", "{{0, 508.86}, {58.62, 14.14}}" ) </code></pre> <p>If there were three lines' worth of matching results, I will get back three sets of the data.</p> <p>I can't help but think I'm missing something very basic about the way I've coded this method, but after hours of staring at it, I'm ready to throw in the towel and ask a friend. Are you that friend, anonymous SO reader? I could use a friend. :-(</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