Skip to content

Commit 66b7dbb

Browse files
committed
convert files to modert obj-c syntax
1 parent cb821bb commit 66b7dbb

2 files changed

Lines changed: 71 additions & 73 deletions

File tree

DynamicGraphView/GraphView.m

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -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;

DynamicGraphView/ViewController.m

Lines changed: 50 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -112,58 +112,56 @@ - (void)viewDidLoad
112112
-(void)setArrayButtonAction {
113113

114114
// set up array for diplay in graphView
115-
NSArray *points = [[NSArray alloc]initWithObjects:
116-
[NSNumber numberWithFloat:0],
117-
[NSNumber numberWithFloat:0],
118-
[NSNumber numberWithFloat:0],
119-
[NSNumber numberWithFloat:13],
120-
[NSNumber numberWithFloat:7],
121-
[NSNumber numberWithFloat:9],
122-
[NSNumber numberWithFloat:20],
123-
[NSNumber numberWithFloat:04],
124-
[NSNumber numberWithFloat:0],
125-
[NSNumber numberWithFloat:0],
126-
[NSNumber numberWithFloat:0],
127-
[NSNumber numberWithFloat:0],
128-
[NSNumber numberWithFloat:0],
129-
[NSNumber numberWithFloat:0],
130-
[NSNumber numberWithFloat:0],
131-
[NSNumber numberWithFloat:0],
132-
[NSNumber numberWithFloat:0],
133-
[NSNumber numberWithFloat:0],
134-
[NSNumber numberWithFloat:0],
135-
[NSNumber numberWithFloat:0],
136-
[NSNumber numberWithFloat:0],
137-
[NSNumber numberWithFloat:0],
138-
[NSNumber numberWithFloat:0],
139-
[NSNumber numberWithFloat:1],
140-
[NSNumber numberWithFloat:2],
141-
[NSNumber numberWithFloat:3],
142-
[NSNumber numberWithFloat:4],
143-
[NSNumber numberWithFloat:5],
144-
[NSNumber numberWithFloat:6],
145-
[NSNumber numberWithFloat:7],
146-
[NSNumber numberWithFloat:8],
147-
[NSNumber numberWithFloat:9],
148-
[NSNumber numberWithFloat:10],
149-
[NSNumber numberWithFloat:11],
150-
[NSNumber numberWithFloat:12],
151-
[NSNumber numberWithFloat:13],
152-
[NSNumber numberWithFloat:14],
153-
[NSNumber numberWithFloat:13],
154-
[NSNumber numberWithFloat:12],
155-
[NSNumber numberWithFloat:11],
156-
[NSNumber numberWithFloat:10],
157-
[NSNumber numberWithFloat:9],
158-
[NSNumber numberWithFloat:8],
159-
[NSNumber numberWithFloat:7],
160-
[NSNumber numberWithFloat:6],
161-
[NSNumber numberWithFloat:5],
162-
[NSNumber numberWithFloat:4],
163-
[NSNumber numberWithFloat:3],
164-
[NSNumber numberWithFloat:2],
165-
[NSNumber numberWithFloat:1],
166-
nil];
115+
NSArray *points = @[@0.0f,
116+
@0.0f,
117+
@0.0f,
118+
@13.0f,
119+
@7.0f,
120+
@9.0f,
121+
@20.0f,
122+
@04,
123+
@0.0f,
124+
@0.0f,
125+
@0.0f,
126+
@0.0f,
127+
@0.0f,
128+
@0.0f,
129+
@0.0f,
130+
@0.0f,
131+
@0.0f,
132+
@0.0f,
133+
@0.0f,
134+
@0.0f,
135+
@0.0f,
136+
@0.0f,
137+
@0.0f,
138+
@1.0f,
139+
@2.0f,
140+
@3.0f,
141+
@4.0f,
142+
@5.0f,
143+
@6.0f,
144+
@7.0f,
145+
@8.0f,
146+
@9.0f,
147+
@10.0f,
148+
@11.0f,
149+
@12.0f,
150+
@13.0f,
151+
@14.0f,
152+
@13.0f,
153+
@12.0f,
154+
@11.0f,
155+
@10.0f,
156+
@9.0f,
157+
@8.0f,
158+
@7.0f,
159+
@6.0f,
160+
@5.0f,
161+
@4.0f,
162+
@3.0f,
163+
@2.0f,
164+
@1.0f];
167165

168166
[graphView setArray:points];
169167
}

0 commit comments

Comments
 (0)