@@ -63,7 +63,7 @@ - (id)initWithFrame:(CGRect)frame
6363
6464 pointArray = [[NSMutableArray alloc ]init]; // stores the energy values
6565 for (int i = 0 ; i < dx; i++) {
66- [pointArray addObject: [ NSNumber numberWithFloat: 0 .0f ] ];
66+ [pointArray addObject: @ 0 .0f ];
6767 }
6868
6969 }
@@ -73,7 +73,7 @@ - (id)initWithFrame:(CGRect)frame
7373
7474-(void )setPoint : (float )point {
7575
76- [pointArray insertObject: [ NSNumber numberWithFloat: point] atIndex: 0 ];
76+ [pointArray insertObject: @( point) atIndex: 0 ];
7777 [pointArray removeObjectAtIndex: [pointArray count ] - 1 ];
7878
7979 [self setNeedsDisplay ];
@@ -83,7 +83,7 @@ -(void)resetGraph {
8383
8484 pointArray = [[NSMutableArray alloc ]init]; // stores the energy values
8585 for (int i = 0 ; i < dx; i++) {
86- [pointArray addObject: [ NSNumber numberWithFloat: 0 .0f ] ];
86+ [pointArray addObject: @ 0 .0f ];
8787 }
8888
8989 [self setNeedsDisplay ];
@@ -150,7 +150,7 @@ -(void)setNumberOfPointsInGraph:(int)numberOfPoints {
150150 int dCount = dx - [pointArray count ];
151151
152152 for (int i = 0 ; i < dCount; i++) {
153- [pointArray addObject: [ NSNumber numberWithFloat: 0 .0f ] ];
153+ [pointArray addObject: @( 0 .0f ) ];
154154 }
155155
156156 }
@@ -203,20 +203,20 @@ - (void)drawRect:(CGRect)rect {
203203 NSMutableArray *points = [[self arrayOfPoints ] mutableCopy ];
204204
205205 // Add control points to make the math make sense
206- [points insertObject: [ points objectAtIndex: 0 ] atIndex: 0 ];
206+ [points insertObject: points[ 0 ] atIndex: 0 ];
207207 [points addObject: [points lastObject ]];
208208
209209 UIBezierPath *lineGraph = [UIBezierPath bezierPath ];
210210
211- [lineGraph moveToPoint: [[ points objectAtIndex: 0 ] CGPointValue ]];
211+ [lineGraph moveToPoint: [points[ 0 ] CGPointValue ]];
212212
213213 for (NSUInteger index = 1 ; index < points.count - 2 ; index++)
214214 {
215215
216- CGPoint p0 = [(NSValue *)[ points objectAtIndex: index - 1 ] CGPointValue ];
217- CGPoint p1 = [(NSValue *)[ points objectAtIndex: index] CGPointValue ];
218- CGPoint p2 = [(NSValue *)[ points objectAtIndex: index + 1 ] CGPointValue ];
219- CGPoint p3 = [(NSValue *)[ points objectAtIndex: index + 2 ] CGPointValue ];
216+ CGPoint p0 = [(NSValue *)points[ index - 1 ] CGPointValue ];
217+ CGPoint p1 = [(NSValue *)points[ index] CGPointValue ];
218+ CGPoint p2 = [(NSValue *)points[ index + 1 ] CGPointValue ];
219+ CGPoint p3 = [(NSValue *)points[ index + 2 ] CGPointValue ];
220220
221221 // now add n points starting at p1 + dx/dy up until p2 using Catmull-Rom splines
222222 for (int i = 1 ; i < granularity; i++)
@@ -236,7 +236,7 @@ - (void)drawRect:(CGRect)rect {
236236 }
237237
238238 // finish by adding the last point
239- [lineGraph addLineToPoint: [(NSValue *)[ points objectAtIndex: (points.count - 1 )] CGPointValue ]];
239+ [lineGraph addLineToPoint: [(NSValue *)points[ (points.count - 1 )] CGPointValue ]];
240240
241241 [fillColor setFill ];
242242 [strokeColor setStroke ];
@@ -257,34 +257,34 @@ - (void)drawRect:(CGRect)rect {
257257
258258}
259259
260- -(NSArray *)arrayOfPoints {
260+ - (NSArray *)arrayOfPoints {
261261
262262 NSMutableArray *points = [NSMutableArray array ];
263263
264- int viewWidth = self.frame . size . width ;
265- int viewHeight = self.frame . size . height ;
264+ int viewWidth = CGRectGetWidth ( self.frame ) ;
265+ int viewHeight = CGRectGetHeight ( self.frame ) ;
266266
267267 for (int i = 0 ; i < [pointArray count ]; i++) {
268268
269269
270270 float point1x = viewWidth - (viewWidth / dx) * i; // start graph x on the right hand side
271- float point1y = (viewHeight - (viewHeight / dy) * [[ pointArray objectAtIndex: i] floatValue]) / setZero; // start graph y on the bottom
271+ float point1y = (viewHeight - (viewHeight / dy) * [pointArray[i] floatValue ]) / setZero; // start graph y on the bottom
272272
273273 float point2x = viewWidth - (viewWidth / dx) * i - (viewWidth / dx);
274274 float point2y = point1y;
275275
276276 if (i != [pointArray count ]-1 ) {
277- point2y = (viewHeight - (viewHeight / dy) * [[ pointArray objectAtIndex: i+1 ]floatValue]) / setZero;
277+ point2y = (viewHeight - (viewHeight / dy) * [pointArray[ i+1 ] floatValue ]) / setZero;
278278 }
279+
280+ CGPoint p;
279281
280282 if (i == 0 ) {
281- CGPoint p1 = CGPointMake (point1x, point1y);
282- [points addObject: [NSValue valueWithCGPoint: p1]];
283+ p = CGPointMake (point1x, point1y);
283284 }else {
284-
285- CGPoint p2 = CGPointMake (point2x, point2y);
286- [points addObject: [NSValue valueWithCGPoint: p2]];
285+ p = CGPointMake (point2x, point2y);
287286 }
287+ [points addObject: [NSValue valueWithCGPoint: p]];
288288 }
289289
290290 return points;
0 commit comments