Note that there are some explanatory texts on larger screens.

plurals
  1. PONSMutableArray not being modified properly when manipulated in other class
    primarykey
    data
    text
    <p>I have an NSMutableArray as a property in a view controller class, and this line is being used in two other classes. One of the classes manipulates the array (adds more objects to it) and another just reads from it. When one of the classes manipulates the array, it is not being modified in the view controller class, which it is instantiated in. Therefore, the third class is not getting the proper date it needs.</p> <p>In the view controller class:</p> <pre><code>@property (nonatomic, strong) NSMutableArray *entityLines; </code></pre> <p>In other two classes:</p> <pre><code>@property (nonatomic, weak) NSMutableArray *linesToDraw; @property (nonatomic, weak) NSMutableArray *linesForKey; </code></pre> <p>Array initialization:</p> <pre><code>- (id)init { self = [super init]; if (self) { self.title = @"Line graph"; lineQuery = [[LineGraphQuery alloc] init]; entityLines = [NSMutableArray array]; } return self; } </code></pre> <p>Modifying array:</p> <pre><code> - (void)drawRect:(CGRect)rect { if(data.namedEntityData.count &gt; 0) { CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetLineWidth(context, LINE_WIDTH); CGContextSetLineCap(context, kCGLineCapRound); CGContextSetFillColorWithColor(context, [[UIColor blackColor] CGColor]); CGContextFillRect(context, rect); [self clearAllLines]; for(NSString *key in [data.namedEntityData allKeys]) { EntityLine *entityLine = [self getNamedEntityLineForName:key]; if(!entityLine) { entityLine = [[EntityLine alloc] init]; entityLine.name = key; entityLine.color = [self getRandomColor]; } float intervalX = STARTING_INTERVAL_X; float lastRangeY = MIN_EVENT_COUNT_Y; CGContextSetStrokeColorWithColor(context, [entityLine.color CGColor]); NSArray *events = [data.namedEntityData objectForKey:key]; NSInteger rangeDifference = data.endYear - data.beginYear; for(int i = 0; i &lt; numberOfDateRangeIntervals; i++) { int startYearRange = data.beginYear + (i * (rangeDifference / numberOfDateRangeIntervals)); int endYearRange = (i == numberOfDateRangeIntervals - 1) ? data.endYear : data.beginYear + ((i + 1) * (rangeDifference / numberOfDateRangeIntervals) - 1); int eventCount = [self getCountForEvents:events withBeginYear:startYearRange andEndYear:endYearRange]; Line *line = [[Line alloc] init]; line.begin = CGPointMake(intervalX, lastRangeY); CGContextMoveToPoint(context, line.begin.x, line.begin.y); intervalX += intervalXIncrement; lastRangeY = [self getYCoordinateForEventCount:eventCount]; line.end = CGPointMake(intervalX, lastRangeY); [entityLine addLine:line]; CGContextAddLineToPoint(context, line.end.x, line.end.y); CGContextStrokePath(context); } [linesToDraw addObject:entityLine]; } [self drawEventCountLabelsWithContext:context]; [self drawDateRangeLabelsWithContext:context]; } } - (void)clearAllLines { for(EntityLine *line in linesToDraw) [line clearLines]; } </code></pre> <p>Other class setting the reference to the NSMutableArray:</p> <pre><code>lineGraph.linesToDraw = self.entityLines; lineKey.linesForKey = self.entityLines; </code></pre>
    singulars
    1. This table or related slice is empty.
    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