Skip to content

Commit 5c5bcf3

Browse files
committed
Convert back to NSInteger in API for Swift compatibility
Enable signed conversion checking and fix issues Fix test for white/alpha to handle extended Grey space
1 parent fd993c0 commit 5c5bcf3

12 files changed

Lines changed: 83 additions & 79 deletions

File tree

Classes/BEMGraphCalculator.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,23 +237,23 @@ - (NSNumber *)calculateCorrelationCoefficientUsingCorrelationMethod:(BEMCorrelat
237237
NSMutableArray <NSNumber *> *xPoints = [NSMutableArray arrayWithCapacity:yPoints.count];
238238
if (scale == nil || scale.floatValue == 0.0) {
239239
for (NSUInteger i = 1; i <= yPoints.count; i++) {
240-
[xPoints addObject:[NSNumber numberWithInteger:i]];
240+
[xPoints addObject:@(i)];
241241
}
242242
} else {
243243
for (NSUInteger i = 1; i <= yPoints.count; i++) {
244-
[xPoints addObject:[NSNumber numberWithFloat:(i*scale.floatValue)]];
244+
[xPoints addObject:@(i*scale.floatValue)];
245245
}
246246
}
247247

248248
// Set the initial values of our sum counts
249-
NSInteger pointsCount = yPoints.count;
249+
NSUInteger pointsCount = yPoints.count;
250250
CGFloat sumY = 0.0;
251251
CGFloat sumX = 0.0;
252252
CGFloat sumXY = 0.0;
253253
CGFloat sumX2 = 0.0;
254254
CGFloat sumY2 = 0.0;
255255

256-
NSInteger iterationCount = 0;
256+
NSUInteger iterationCount = 0;
257257
for (NSNumber *yPoint in yPoints) {
258258
NSNumber *xPoint = xPoints[iterationCount];
259259
iterationCount++;

Classes/BEMLine.m

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,19 +153,19 @@ - (void)drawRect:(CGRect)rect {
153153

154154
} else if (value == self.points[numPoints-1]) {
155155
//extrapolate a right edge poit from previous two actual values
156-
NSInteger firstPos = numPoints-2; //look for first real value
157-
while (firstPos >= 0 && self.points[firstPos].CGPointValue.y >= BEMNullGraphValue) firstPos--;
156+
NSInteger firstPos = ((NSInteger)numPoints)-2; //look for first real value
157+
while (firstPos >= 0 && self.points[(NSUInteger)firstPos].CGPointValue.y >= BEMNullGraphValue) firstPos--;
158158
if (firstPos < 0 ) continue; // all NaNs?? =>don't create any line; should already be gone
159159

160-
CGFloat firstValue = self.points[firstPos].CGPointValue.y;
160+
CGFloat firstValue = self.points[(NSUInteger)firstPos].CGPointValue.y;
161161
NSInteger secondPos = firstPos-1; //look for second real value
162-
while (secondPos >= 0 && self.points[secondPos].CGPointValue.y >= BEMNullGraphValue) secondPos--;
162+
while (secondPos >= 0 && self.points[(NSUInteger)secondPos].CGPointValue.y >= BEMNullGraphValue) secondPos--;
163163
if (secondPos < 0) {
164164
// only one real number
165165
yValue = firstValue;
166166
} else {
167-
CGFloat delta = firstValue - self.points[secondPos].CGPointValue.y;
168-
yValue = firstValue + (numPoints - firstPos-1)*delta/(firstPos - secondPos);
167+
CGFloat delta = firstValue - self.points[(NSUInteger)secondPos].CGPointValue.y;
168+
yValue = firstValue + ((NSInteger)numPoints - firstPos-1)*delta/(firstPos - secondPos);
169169
}
170170

171171
} else {

Classes/BEMSimpleLineGraphView.h

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -162,15 +162,15 @@ IB_DESIGNABLE @interface BEMSimpleLineGraphView : UIView <UIGestureRecognizerDel
162162

163163
/** The number of fingers required to report touches to the graph's delegate. The default value is 1.
164164
@discussion Setting this value to greater than 1 might be beneficial in interfaces that allow the graph to scroll and still want to use touch reporting. */
165-
@property (nonatomic) NSUInteger touchReportFingersRequired;
165+
@property (nonatomic) NSInteger touchReportFingersRequired;
166166

167167

168168
/// If set to YES, a label will pop up on the graph when the user touches it. It will be displayed on top of the closest point from the user current touch location. Default value is NO.
169169
@property (nonatomic) BOOL enablePopUpReport;
170170

171171

172172
/// If set to YES, the graph will react to pinch/zoom gesture to allow user to focus on one section of data. When zoomed, double-finger paning means "move graph" and double-tap will restore scale. Default value is NO.
173-
@property (nonatomic) BOOL enableUserScaling;
173+
@property (nonatomic) IBInspectable BOOL enableUserScaling;
174174

175175
/// Current zoom level; normally set by user through pinch/zoom gestures. Min value is 1.0, which means all data should be displayed.
176176
@property (nonatomic) CGFloat zoomScale;
@@ -402,14 +402,14 @@ IB_DESIGNABLE @interface BEMSimpleLineGraphView : UIView <UIGestureRecognizerDel
402402
/** The number of points along the X-axis of the graph.
403403
@param graph The graph object requesting the total number of points.
404404
@return The total number of points in the line graph. */
405-
- (NSUInteger)numberOfPointsInLineGraph:(BEMSimpleLineGraphView *)graph;
405+
- (NSInteger)numberOfPointsInLineGraph:(BEMSimpleLineGraphView *)graph;
406406

407407

408408
/** The vertical position for a point at the given index. It corresponds to the Y-axis value of the Graph.
409409
@param graph The graph object requesting the point value.
410410
@param index The index from left to right of a given point (X-axis). The first value for the index is 0.
411411
@return The Y-axis value at a given index. */
412-
- (CGFloat)lineGraph:(BEMSimpleLineGraphView *)graph valueForPointAtIndex:(NSUInteger)index;
412+
- (CGFloat)lineGraph:(BEMSimpleLineGraphView *)graph valueForPointAtIndex:(NSInteger)index;
413413

414414

415415
@optional
@@ -421,7 +421,7 @@ IB_DESIGNABLE @interface BEMSimpleLineGraphView : UIView <UIGestureRecognizerDel
421421
@discussion The number of strings to be returned should be equal to the number of points in the graph (returned in \p numberOfPointsInLineGraph). Otherwise, an exception may be thrown.
422422
@param graph The graph object which is requesting the label on the specified X-Axis position.
423423
@param index The index from left to right of a given label on the X-axis. Is the same index as the one for the points. The first value for the index is 0. */
424-
- (nullable NSString *)lineGraph:(nonnull BEMSimpleLineGraphView *)graph labelOnXAxisForIndex:(NSUInteger)index;
424+
- (nullable NSString *)lineGraph:(nonnull BEMSimpleLineGraphView *)graph labelOnXAxisForIndex:(NSInteger)index;
425425

426426
/** The string to display on the label on the X-axis at a given location.
427427
@discussion Use this instead of labelOnXAxisForIndex when you have implemented locationForPointAtIndex.
@@ -475,7 +475,7 @@ IB_DESIGNABLE @interface BEMSimpleLineGraphView : UIView <UIGestureRecognizerDel
475475
/** The optional text for the popup report.
476476
@param graph The graph object requesting the total number of points.
477477
@return The text to substitute for the popup. If nil is returned, the popup text will be derived using the given data point and any supplied suffix and / or prefix. */
478-
- (nullable NSString *)popUpTextForlineGraph:(BEMSimpleLineGraphView *)graph atIndex:(NSUInteger)index;
478+
- (nullable NSString *)popUpTextForlineGraph:(BEMSimpleLineGraphView *)graph atIndex:(NSInteger)index;
479479

480480

481481
/** The optional suffix to append to the popup report.
@@ -495,7 +495,7 @@ IB_DESIGNABLE @interface BEMSimpleLineGraphView : UIView <UIGestureRecognizerDel
495495
@param graph The graph object requesting the total number of points.
496496
@param index The index from left to right of the points on the graph. The first value for the index is 0.
497497
@return Return YES if you want the popup label to be displayed for this index. */
498-
- (BOOL)lineGraph:(BEMSimpleLineGraphView *)graph alwaysDisplayPopUpAtIndex:(NSUInteger)index;
498+
- (BOOL)lineGraph:(BEMSimpleLineGraphView *)graph alwaysDisplayPopUpAtIndex:(NSInteger)index;
499499

500500

501501
/** Optional method to set the maximum value of the Y-Axis. If not implemented, the maximum value will be the biggest point of the graph.
@@ -553,7 +553,7 @@ IB_DESIGNABLE @interface BEMSimpleLineGraphView : UIView <UIGestureRecognizerDel
553553
@param graph The graph object requesting the padding value.
554554
@param popupView The popup view owned by the graph that needs to be modified
555555
@param index The index of the element associated with the popup view */
556-
- (void)lineGraph:(BEMSimpleLineGraphView *)graph modifyPopupView:(UIView *)popupView forIndex:(NSUInteger)index;
556+
- (void)lineGraph:(BEMSimpleLineGraphView *)graph modifyPopupView:(UIView *)popupView forIndex:(NSInteger)index;
557557

558558

559559
//----- TOUCH EVENTS -----//
@@ -562,7 +562,7 @@ IB_DESIGNABLE @interface BEMSimpleLineGraphView : UIView <UIGestureRecognizerDel
562562
/** Sent to the delegate when the user starts touching the graph. The property 'enableTouchReport' must be set to YES.
563563
@param graph The graph object which was touched by the user.
564564
@param index The closest index (X-axis) from the location the user is currently touching. */
565-
- (void)lineGraph:(BEMSimpleLineGraphView *)graph didTouchGraphWithClosestIndex:(NSUInteger)index;
565+
- (void)lineGraph:(BEMSimpleLineGraphView *)graph didTouchGraphWithClosestIndex:(NSInteger)index;
566566

567567

568568
/** Sent to the delegate when the user stops touching the graph.
@@ -578,21 +578,21 @@ IB_DESIGNABLE @interface BEMSimpleLineGraphView : UIView <UIGestureRecognizerDel
578578
@discussion For example returning '1' would mean that half of the labels on the X-axis are not displayed: the first is not displayed, the second is, the third is not etc. Returning '0' would mean that all of the labels will be displayed. Finally, returning a value equal to the number of labels will only display the first and last label.
579579
@param graph The graph object which is requesting the number of gaps between the labels.
580580
@return The number of labels to "jump" between each displayed label on the X-axis. */
581-
- (NSUInteger)numberOfGapsBetweenLabelsOnLineGraph:(BEMSimpleLineGraphView *)graph;
581+
- (NSInteger)numberOfGapsBetweenLabelsOnLineGraph:(BEMSimpleLineGraphView *)graph;
582582

583583

584584
/** The starting index to plot X-Axis values. MUST ALSO IMPLEMENT incrementIndexForXAxisOnLineGraph FOR THIS TO TAKE EFFECT
585585
@discussion This allows you to specify a custom starting index for drawing x axis labels
586586
@param graph The graph object which is requesting the number of gaps between the labels.
587587
@return The graph data index to begin drawing labels */
588-
- (NSUInteger)baseIndexForXAxisOnLineGraph:(BEMSimpleLineGraphView *)graph;
588+
- (NSInteger)baseIndexForXAxisOnLineGraph:(BEMSimpleLineGraphView *)graph;
589589

590590

591591
/** The increment to apply when drawing X-Axis labels. This increment is applied to the base x axis index. MUST ALSO IMPLEMENT baseIndexForXAxisOnLineGraph FOR THIS TO TAKE EFFECT
592592
@discussion This allows you to set a custom interval in drawing x axis labels. When this is set in conjuction with baseIndexForXAxisOnLineGraph, `numberOfGapsBetweenLabelsOnLineGraph` is ignored
593593
@param graph The graph object which is requesting the number of gaps between the labels.
594594
@return The increment between X-Axis labels */
595-
- (NSUInteger)incrementIndexForXAxisOnLineGraph:(BEMSimpleLineGraphView *)graph;
595+
- (NSInteger)incrementIndexForXAxisOnLineGraph:(BEMSimpleLineGraphView *)graph;
596596

597597

598598
/** An array of graph indices where X-Axis labels should be drawn
@@ -608,7 +608,7 @@ IB_DESIGNABLE @interface BEMSimpleLineGraphView : UIView <UIGestureRecognizerDel
608608
@param graph The graph object requesting the point value.
609609
@param index The index from left to right of a given point (X-axis). The first value for the index is 0.
610610
@return The X-axis value at a given index. */
611-
- (CGFloat)lineGraph:(BEMSimpleLineGraphView *)graph locationForPointAtIndex:(NSUInteger)index;
611+
- (CGFloat)lineGraph:(BEMSimpleLineGraphView *)graph locationForPointAtIndex:(NSInteger)index;
612612

613613
/** The total number of X-axis labels on the line graph.
614614
@discussion Calculates the total wdith of the graph and evenly spaces the labels based on the graph width. If this and lineGraph:locationForPointAtIndex: are implemented, labels may diverge from data points
@@ -632,7 +632,7 @@ IB_DESIGNABLE @interface BEMSimpleLineGraphView : UIView <UIGestureRecognizerDel
632632
@discussion Calculates the total height of the graph and evenly spaces the labels based on the graph height. Default value is 3.
633633
@param graph The graph object which is requesting the number of labels.
634634
@return The number of labels displayed on the Y-axis. */
635-
- (NSUInteger)numberOfYAxisLabelsOnLineGraph:(BEMSimpleLineGraphView *)graph;
635+
- (NSInteger)numberOfYAxisLabelsOnLineGraph:(BEMSimpleLineGraphView *)graph;
636636

637637

638638
/** The optional prefix to append to the y axis.

Classes/BEMSimpleLineGraphView.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ @interface BEMSimpleLineGraphView ()
2828
#pragma mark Properties to store data and computed locations
2929
/// The number of Points in the Graph
3030
/// Set by layoutself.numberOfPoints
31-
@property (assign, nonatomic ) NSUInteger numberOfPoints;
31+
@property (assign, nonatomic ) NSInteger numberOfPoints;
3232

3333
/// All of the Data Points from datasource (Y values)
3434
/// Set by getData and used throughout.
@@ -893,7 +893,7 @@ - (void)drawXAxis {
893893
if (indexLabels) {
894894
xAxisLabelText = [self.dataSource lineGraph:self labelOnXAxisForIndex:realIndex ];
895895
} else {
896-
xAxisLabelText = [NSString stringWithFormat:@"%lu", realIndex];
896+
xAxisLabelText = [NSString stringWithFormat:@"%lu", (long)realIndex];
897897
}
898898
}
899899
[newAxisLabelTexts addObject:xAxisLabelText];
@@ -1346,7 +1346,7 @@ -(CGFloat) xValueForLocation: (CGFloat) location {
13461346
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
13471347
CGFloat xLoc = [gestureRecognizer locationInView:self.labelsView].x;
13481348
if ([gestureRecognizer isEqual:self.touchReportPanGesture]) {
1349-
if (gestureRecognizer.numberOfTouches >= self.touchReportFingersRequired) {
1349+
if ((NSInteger)gestureRecognizer.numberOfTouches >= self.touchReportFingersRequired) {
13501350
CGPoint translation = [self.touchReportPanGesture velocityInView:self.labelsView];
13511351
return fabs(translation.y) < fabs(translation.x);
13521352
} else {

Sample Project/SimpleLineChart.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,7 @@
641641
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
642642
CLANG_WARN_EMPTY_BODY = YES;
643643
CLANG_WARN_ENUM_CONVERSION = YES;
644+
CLANG_WARN_IMPLICIT_SIGN_CONVERSION = YES;
644645
CLANG_WARN_INFINITE_RECURSION = YES;
645646
CLANG_WARN_INT_CONVERSION = YES;
646647
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
@@ -698,6 +699,7 @@
698699
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
699700
CLANG_WARN_EMPTY_BODY = YES;
700701
CLANG_WARN_ENUM_CONVERSION = YES;
702+
CLANG_WARN_IMPLICIT_SIGN_CONVERSION = YES;
701703
CLANG_WARN_INFINITE_RECURSION = YES;
702704
CLANG_WARN_INT_CONVERSION = YES;
703705
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;

Sample Project/SimpleLineChart/ViewController.m

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ - (void)hydrateDatasets {
101101
BOOL showNullValue = YES;
102102

103103
// Add objects to the array based on the stepper value
104-
for (int i = 0; i < 9; i++) {
104+
for (NSUInteger i = 0; i < 9; i++) {
105105
[self.arrayOfValues addObject:@([self getRandomFloat])]; // Random values for the graph
106106
if (i == 0) {
107107
[self.arrayOfDates addObject:baseDate]; // Dates for the X-Axis of the graph
@@ -123,7 +123,7 @@ - (NSDate *)dateForGraphAfterDate:(NSDate *)date {
123123
}
124124

125125
- (NSString *)labelForDateAtIndex:(NSInteger)index {
126-
NSDate *date = self.arrayOfDates[index];
126+
NSDate *date = self.arrayOfDates[(NSUInteger)index];
127127
NSDateFormatter *df = [[NSDateFormatter alloc] init];
128128
df.dateFormat = @"MM/dd";
129129
NSString *label = [df stringFromDate:date];
@@ -203,28 +203,28 @@ - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
203203

204204
#pragma mark - SimpleLineGraph Data Source
205205

206-
- (NSUInteger)numberOfPointsInLineGraph:(BEMSimpleLineGraphView *)graph {
206+
- (NSInteger)numberOfPointsInLineGraph:(BEMSimpleLineGraphView *)graph {
207207
return (int)[self.arrayOfValues count];
208208
}
209209

210-
- (CGFloat)lineGraph:(BEMSimpleLineGraphView *)graph valueForPointAtIndex:(NSUInteger)index {
211-
return [[self.arrayOfValues objectAtIndex:index] doubleValue];
210+
- (CGFloat)lineGraph:(BEMSimpleLineGraphView *)graph valueForPointAtIndex:(NSInteger)index {
211+
return self.arrayOfValues [(NSUInteger)index].doubleValue;
212212
}
213213

214214
#pragma mark - SimpleLineGraph Delegate
215215

216-
- (NSUInteger)numberOfGapsBetweenLabelsOnLineGraph:(BEMSimpleLineGraphView *)graph {
216+
- (NSInteger)numberOfGapsBetweenLabelsOnLineGraph:(BEMSimpleLineGraphView *)graph {
217217
return 2;
218218
}
219219

220-
- (NSString *)lineGraph:(BEMSimpleLineGraphView *)graph labelOnXAxisForIndex:(NSUInteger)index {
220+
- (NSString *)lineGraph:(BEMSimpleLineGraphView *)graph labelOnXAxisForIndex:(NSInteger)index {
221221

222222
NSString *label = [self labelForDateAtIndex:index];
223223
return [label stringByReplacingOccurrencesOfString:@" " withString:@"\n"];
224224
}
225225

226-
- (void)lineGraph:(BEMSimpleLineGraphView *)graph didTouchGraphWithClosestIndex:(NSUInteger)index {
227-
self.labelValues.text = [NSString stringWithFormat:@"%@", [self.arrayOfValues objectAtIndex:index]];
226+
- (void)lineGraph:(BEMSimpleLineGraphView *)graph didTouchGraphWithClosestIndex:(NSInteger)index {
227+
self.labelValues.text = [NSString stringWithFormat:@"%@", self.arrayOfValues [(NSUInteger)index]];
228228
self.labelDates.text = [NSString stringWithFormat:@"in %@", [self labelForDateAtIndex:index]];
229229
}
230230

@@ -234,7 +234,7 @@ - (void)lineGraph:(BEMSimpleLineGraphView *)graph didReleaseTouchFromGraphWithCl
234234
self.labelDates.alpha = 0.0f;
235235
} completion:^(BOOL finished) {
236236
self.labelValues.text = [NSString stringWithFormat:@"%i", [[[BEMGraphCalculator sharedCalculator] calculatePointValueSumOnGraph:self.myGraph] intValue]];
237-
self.labelDates.text = [NSString stringWithFormat:@"between %@ and %@", [self labelForDateAtIndex:0], [self labelForDateAtIndex:self.arrayOfDates.count - 1]];
237+
self.labelDates.text = [NSString stringWithFormat:@"between %@ and %@", [self labelForDateAtIndex:0], [self labelForDateAtIndex:(NSInteger)(self.arrayOfDates.count) - 1]];
238238

239239
[UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
240240
self.labelValues.alpha = 1.0f;
@@ -247,7 +247,7 @@ - (void)lineGraphDidFinishLoading:(BEMSimpleLineGraphView *)graph {
247247
if (self.arrayOfValues.count > 0) {
248248
NSNumber *pointSum = [[BEMGraphCalculator sharedCalculator] calculatePointValueSumOnGraph:self.myGraph];
249249
self.labelValues.text = [NSString stringWithFormat:@"%i", [pointSum intValue]];
250-
self.labelDates.text = [NSString stringWithFormat:@"between %@ and %@", [self labelForDateAtIndex:0], [self labelForDateAtIndex:self.arrayOfDates.count - 1]];
250+
self.labelDates.text = [NSString stringWithFormat:@"between %@ and %@", [self labelForDateAtIndex:0], [self labelForDateAtIndex:(NSInteger)(self.arrayOfDates.count) - 1]];
251251
} else {
252252
self.labelValues.text = @"No data";
253253
self.labelDates.text = @"";

Sample Project/SimpleLineChartTests/CustomizationTests.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@ - (void)setUp {
4040

4141
#pragma mark BEMSimpleLineGraph Data Source
4242

43-
- (NSUInteger)numberOfPointsInLineGraph:(BEMSimpleLineGraphView * __nonnull)graph {
44-
return numberOfPoints;
43+
- (NSInteger)numberOfPointsInLineGraph:(BEMSimpleLineGraphView * __nonnull)graph {
44+
return (NSInteger)numberOfPoints;
4545
}
4646

47-
- (CGFloat)lineGraph:(BEMSimpleLineGraphView * __nonnull)graph valueForPointAtIndex:(NSUInteger)index {
47+
- (CGFloat)lineGraph:(BEMSimpleLineGraphView * __nonnull)graph valueForPointAtIndex:(NSInteger)index {
4848
return pointValue;
4949
}
5050

51-
- (NSString *)lineGraph:(nonnull BEMSimpleLineGraphView *)graph labelOnXAxisForIndex:(NSUInteger)index {
51+
- (NSString *)lineGraph:(nonnull BEMSimpleLineGraphView *)graph labelOnXAxisForIndex:(NSInteger)index {
5252
return xAxisLabelString;
5353
}
5454

0 commit comments

Comments
 (0)