Skip to content

Commit c1cfc68

Browse files
committed
Converted the Plot Gallery example app to modern Objective-C syntax with Xcode 7.2.1.
1 parent ef1ec2b commit c1cfc68

19 files changed

Lines changed: 66 additions & 66 deletions

‎examples/CorePlotGallery/src/ios/AppDelegate.m‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ -(BOOL)application:(nonnull UIApplication *)application didFinishLaunchingWithOp
2525
UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
2626
splitViewController.delegate = self;
2727

28-
UINavigationController *navigationController = [splitViewController.viewControllers lastObject];
28+
UINavigationController *navigationController = splitViewController.viewControllers.lastObject;
2929
navigationController.topViewController.navigationItem.leftBarButtonItem = splitViewController.displayModeButtonItem;
3030

3131
return YES;
@@ -35,7 +35,7 @@ -(BOOL)application:(nonnull UIApplication *)application didFinishLaunchingWithOp
3535

3636
-(BOOL)splitViewController:(UISplitViewController *)splitViewController collapseSecondaryViewController:(UIViewController *)secondaryViewController ontoPrimaryViewController:(UIViewController *)primaryViewController
3737
{
38-
if ( [secondaryViewController isKindOfClass:[UINavigationController class]] && [[(UINavigationController *) secondaryViewController topViewController] isKindOfClass:[DetailViewController class]] && ([(DetailViewController *)[(UINavigationController *) secondaryViewController topViewController] detailItem] == nil) ) {
38+
if ( [secondaryViewController isKindOfClass:[UINavigationController class]] && [( (UINavigationController *)secondaryViewController ).topViewController isKindOfClass:[DetailViewController class]] && ( ( (DetailViewController *)( (UINavigationController *)secondaryViewController ).topViewController ).detailItem == nil ) ) {
3939
// Return YES to indicate that we have handled the collapse by doing nothing; the secondary controller will be discarded.
4040
return YES;
4141
}

‎examples/CorePlotGallery/src/ios/RootViewController.m‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@ -(void)dealloc
5050
-(void)prepareForSegue:(nonnull UIStoryboardSegue *)segue sender:(nullable id)sender
5151
{
5252
if ( [segue.identifier isEqualToString:@"showDetail"] ) {
53-
DetailViewController *controller = (DetailViewController *)[segue.destinationViewController topViewController];
53+
DetailViewController *controller = (DetailViewController *)( (UINavigationController *)segue.destinationViewController ).topViewController;
5454

5555
controller.navigationItem.leftBarButtonItem = self.splitViewController.displayModeButtonItem;
5656
controller.navigationItem.leftItemsSupplementBackButton = YES;
5757

5858
controller.currentThemeName = self.currentThemeName;
5959

60-
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
60+
NSIndexPath *indexPath = self.tableView.indexPathForSelectedRow;
6161

6262
PlotItem *plotItem = [[PlotGallery sharedPlotGallery] objectInSection:[indexPath indexAtPosition:0]
6363
atIndex:[indexPath indexAtPosition:1]];
@@ -84,7 +84,7 @@ -(void)themeChanged:(nonnull NSNotification *)notification
8484

8585
-(NSInteger)numberOfSectionsInTableView:(nonnull UITableView *)tv
8686
{
87-
return (NSInteger)[[PlotGallery sharedPlotGallery] numberOfSections];
87+
return (NSInteger)[PlotGallery sharedPlotGallery].numberOfSections;
8888
}
8989

9090
-(NSInteger)tableView:(nonnull UITableView *)tv numberOfRowsInSection:(NSInteger)section
@@ -113,7 +113,7 @@ -(nonnull UITableViewCell *)tableView:(nonnull UITableView *)tv cellForRowAtInde
113113

114114
-(nullable NSString *)tableView:(nonnull UITableView *)tableView titleForHeaderInSection:(NSInteger)section
115115
{
116-
return [[PlotGallery sharedPlotGallery] sectionTitles][(NSUInteger)section];
116+
return [PlotGallery sharedPlotGallery].sectionTitles[(NSUInteger)section];
117117
}
118118

119119
@end

‎examples/CorePlotGallery/src/mac/PlotGalleryController.m‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,15 @@ -(void)awakeFromNib
5353
{
5454
[[PlotGallery sharedPlotGallery] sortByTitle];
5555

56-
[self.splitView setDelegate:self];
56+
(self.splitView).delegate = self;
5757

5858
[self.imageBrowser setDelegate:self];
5959
[self.imageBrowser setDataSource:self];
6060
[self.imageBrowser setCellsStyleMask:IKCellsStyleShadowed | IKCellsStyleTitled]; // | IKCellsStyleSubtitled];
6161

6262
[self.imageBrowser reloadData];
6363

64-
[self.hostingView setDelegate:self];
64+
(self.hostingView).delegate = self;
6565

6666
[self setupThemes];
6767

@@ -159,7 +159,7 @@ -(void)setPlotItem:(nullable PlotItem *)item
159159

160160
-(NSUInteger)numberOfItemsInImageBrowser:(nonnull IKImageBrowserView *)browser
161161
{
162-
return [[PlotGallery sharedPlotGallery] count];
162+
return [PlotGallery sharedPlotGallery].count;
163163
}
164164

165165
-(nonnull id)imageBrowser:(nonnull IKImageBrowserView *)browser itemAtIndex:(NSUInteger)index
@@ -169,12 +169,12 @@ -(nonnull id)imageBrowser:(nonnull IKImageBrowserView *)browser itemAtIndex:(NSU
169169

170170
-(NSUInteger)numberOfGroupsInImageBrowser:(nonnull IKImageBrowserView *)aBrowser
171171
{
172-
return [[PlotGallery sharedPlotGallery] numberOfSections];
172+
return [PlotGallery sharedPlotGallery].numberOfSections;
173173
}
174174

175175
-(nonnull CPTDictionary)imageBrowser:(nonnull IKImageBrowserView *)aBrowser groupAtIndex:(NSUInteger)index
176176
{
177-
NSString *groupTitle = [[PlotGallery sharedPlotGallery] sectionTitles][index];
177+
NSString *groupTitle = [PlotGallery sharedPlotGallery].sectionTitles[index];
178178

179179
NSUInteger offset = 0;
180180

@@ -196,7 +196,7 @@ -(nonnull CPTDictionary)imageBrowser:(nonnull IKImageBrowserView *)aBrowser grou
196196

197197
-(void)imageBrowserSelectionDidChange:(nonnull IKImageBrowserView *)browser
198198
{
199-
NSUInteger index = [[browser selectionIndexes] firstIndex];
199+
NSUInteger index = [browser selectionIndexes].firstIndex;
200200

201201
if ( index != NSNotFound ) {
202202
PlotItem *item = [[PlotGallery sharedPlotGallery] objectInSection:0 atIndex:index];
@@ -220,22 +220,22 @@ -(CGFloat)splitView:(nonnull NSSplitView *)sv constrainMaxCoordinate:(CGFloat)co
220220
-(void)splitView:(nonnull NSSplitView *)sender resizeSubviewsWithOldSize:(NSSize)oldSize
221221
{
222222
// Lock the LHS width
223-
NSRect frame = [sender frame];
224-
NSView *lhs = [sender subviews][0];
225-
NSRect lhsRect = [lhs frame];
226-
NSView *rhs = [sender subviews][1];
227-
NSRect rhsRect = [rhs frame];
223+
NSRect frame = sender.frame;
224+
NSView *lhs = sender.subviews[0];
225+
NSRect lhsRect = lhs.frame;
226+
NSView *rhs = sender.subviews[1];
227+
NSRect rhsRect = rhs.frame;
228228

229-
CGFloat dividerThickness = [sender dividerThickness];
229+
CGFloat dividerThickness = sender.dividerThickness;
230230

231231
lhsRect.size.height = frame.size.height;
232232

233233
rhsRect.size.width = frame.size.width - lhsRect.size.width - dividerThickness;
234234
rhsRect.size.height = frame.size.height;
235235
rhsRect.origin.x = lhsRect.size.width + dividerThickness;
236236

237-
[lhs setFrame:lhsRect];
238-
[rhs setFrame:rhsRect];
237+
lhs.frame = lhsRect;
238+
rhs.frame = rhsRect;
239239
}
240240

241241
@end

‎examples/CorePlotGallery/src/mac/PlotView.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
@end
1313

14-
@interface PlotView : NSView
14+
@interface PlotView : NSView<PlotViewDelegate>
1515
@property (nonatomic, weak, nullable) id<PlotViewDelegate> delegate;
1616

1717
@end

‎examples/CorePlotGallery/src/plots/CompositePlot.m‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ -(void)renderInView:(nonnull PlotGalleryNativeView *)hostingView withTheme:(null
168168
constant:0.0]];
169169

170170
#else
171-
NSRect viewRect = [hostingView bounds];
171+
NSRect viewRect = hostingView.bounds;
172172

173173
scatterView.frame = NSMakeRect( 0.0,
174174
0.0,
@@ -187,7 +187,7 @@ -(void)renderInView:(nonnull PlotGalleryNativeView *)hostingView withTheme:(null
187187

188188
for ( NSView *view in @[scatterView, barView, pieView] ) {
189189
[view setAutoresizesSubviews:YES];
190-
[view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
190+
view.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
191191

192192
[hostingView addSubview:view];
193193
}
@@ -364,7 +364,7 @@ -(void)renderBarPlotInHostingView:(nonnull CPTGraphHostingView *)hostingView wit
364364
CPTNumberArray customTickLocations = @[@1, @5, @10, @15];
365365
CPTStringArray xAxisLabels = @[@"Label A", @"Label B", @"Label C", @"Label D"];
366366
NSUInteger labelLocation = 0;
367-
CPTMutableAxisLabelSet customLabels = [NSMutableSet setWithCapacity:[xAxisLabels count]];
367+
CPTMutableAxisLabelSet customLabels = [NSMutableSet setWithCapacity:xAxisLabels.count];
368368
for ( NSNumber *tickLocation in customTickLocations ) {
369369
CPTAxisLabel *newLabel = [[CPTAxisLabel alloc] initWithText:xAxisLabels[labelLocation++] textStyle:x.labelTextStyle];
370370
newLabel.tickLocation = tickLocation;
@@ -470,7 +470,7 @@ -(void)plotAreaWasSelected:(nonnull CPTPlotArea *)plotArea
470470
-(NSUInteger)numberOfRecordsForPlot:(nonnull CPTPlot *)plot
471471
{
472472
if ( [plot isKindOfClass:[CPTPieChart class]] ) {
473-
return [self.dataForChart count];
473+
return self.dataForChart.count;
474474
}
475475
else if ( [plot isKindOfClass:[CPTBarPlot class]] ) {
476476
return 16;
@@ -485,7 +485,7 @@ -(nullable id)numberForPlot:(nonnull CPTPlot *)plot field:(NSUInteger)fieldEnum
485485
NSNumber *num = nil;
486486

487487
if ( [plot isKindOfClass:[CPTPieChart class]] ) {
488-
if ( index >= [self.dataForChart count] ) {
488+
if ( index >= self.dataForChart.count ) {
489489
return nil;
490490
}
491491

@@ -517,7 +517,7 @@ -(nullable id)numberForPlot:(nonnull CPTPlot *)plot field:(NSUInteger)fieldEnum
517517
// Green plot gets shifted above the blue
518518
if ( [(NSString *) plot.identifier isEqualToString:@"Green Plot"] ) {
519519
if ( fieldEnum == CPTScatterPlotFieldY ) {
520-
num = @([num doubleValue] + 1.0);
520+
num = @(num.doubleValue + 1.0);
521521
}
522522
}
523523
}

‎examples/CorePlotGallery/src/plots/ControlChart.m‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ -(void)generateData
5555

5656
sum = 0.0;
5757
for ( NSNumber *value in contentArray ) {
58-
double error = [value doubleValue] - self.meanValue;
58+
double error = value.doubleValue - self.meanValue;
5959
sum += error * error;
6060
}
6161
double stdDev = sqrt( ( 1.0 / (numberOfPoints - 1) ) * sum );
@@ -255,7 +255,7 @@ -(double)doubleForPlot:(nonnull CPTPlot *)plot field:(NSUInteger)fieldEnum recor
255255

256256
case CPTScatterPlotFieldY:
257257
if ( plot.identifier == kDataLine ) {
258-
number = [self.plotData[index] doubleValue];
258+
number = (self.plotData[index]).doubleValue;
259259
}
260260
else if ( plot.identifier == kCenterLine ) {
261261
number = self.meanValue;

‎examples/CorePlotGallery/src/plots/CurvedScatterPlot.m‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,13 @@ -(void)generateData
8383
NSDictionary<NSString *, NSNumber *> *point1 = dataArray[i - 1];
8484
NSDictionary<NSString *, NSNumber *> *point2 = dataArray[i];
8585

86-
double x1 = [point1[@"x"] doubleValue];
87-
double x2 = [point2[@"x"] doubleValue];
86+
double x1 = (point1[@"x"]).doubleValue;
87+
double x2 = (point2[@"x"]).doubleValue;
8888
double dx = x2 - x1;
8989
double xLoc = (x1 + x2) * 0.5;
9090

91-
double y1 = [point1[@"y"] doubleValue];
92-
double y2 = [point2[@"y"] doubleValue];
91+
double y1 = (point1[@"y"]).doubleValue;
92+
double y2 = (point2[@"y"]).doubleValue;
9393
double dy = y2 - y1;
9494

9595
[contentArray addObject:
@@ -110,13 +110,13 @@ -(void)generateData
110110
NSDictionary<NSString *, NSNumber *> *point1 = dataArray[i - 1];
111111
NSDictionary<NSString *, NSNumber *> *point2 = dataArray[i];
112112

113-
double x1 = [point1[@"x"] doubleValue];
114-
double x2 = [point2[@"x"] doubleValue];
113+
double x1 = (point1[@"x"]).doubleValue;
114+
double x2 = (point2[@"x"]).doubleValue;
115115
double dx = x2 - x1;
116116
double xLoc = (x1 + x2) * 0.5;
117117

118-
double y1 = [point1[@"y"] doubleValue];
119-
double y2 = [point2[@"y"] doubleValue];
118+
double y1 = (point1[@"y"]).doubleValue;
119+
double y2 = (point2[@"y"]).doubleValue;
120120
double dy = y2 - y1;
121121

122122
[contentArray addObject:
@@ -395,7 +395,7 @@ -(void)scatterPlot:(nonnull CPTScatterPlot *)plot plotSymbolWasSelectedAtRecordI
395395
// Add annotation
396396
// First make a string for the y value
397397
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
398-
[formatter setMaximumFractionDigits:2];
398+
formatter.maximumFractionDigits = 2;
399399
NSString *yString = [formatter stringFromNumber:y];
400400

401401
// Now add the annotation to the plot area
@@ -442,7 +442,7 @@ -(void)plotAreaWasSelected:(nonnull CPTPlotArea *)plotArea
442442
CPTPlotSpaceAnnotation *annotation = self.symbolTextAnnotation;
443443

444444
if ( annotation ) {
445-
CPTXYGraph *graph = [self.graphs objectAtIndex:0];
445+
CPTXYGraph *graph = (self.graphs)[0];
446446

447447
[graph.plotAreaFrame.plotArea removeAnnotation:annotation];
448448
self.symbolTextAnnotation = nil;

‎examples/CorePlotGallery/src/plots/DatePlot.m‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@ -(void)renderInGraphHostingView:(nonnull CPTGraphHostingView *)hostingView withT
6060
// for daylight savings time.
6161
NSDateComponents *dateComponents = [[NSDateComponents alloc] init];
6262

63-
[dateComponents setMonth:10];
64-
[dateComponents setDay:29];
65-
[dateComponents setYear:2009];
66-
[dateComponents setHour:12];
67-
[dateComponents setMinute:0];
68-
[dateComponents setSecond:0];
63+
dateComponents.month = 10;
64+
dateComponents.day = 29;
65+
dateComponents.year = 2009;
66+
dateComponents.hour = 12;
67+
dateComponents.minute = 0;
68+
dateComponents.second = 0;
6969

7070
NSCalendar *gregorian = [[NSCalendar alloc]
7171
initWithCalendarIdentifier:NSCalendarIdentifierGregorian];

‎examples/CorePlotGallery/src/plots/DonutChart.m‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ -(nullable CPTLayer *)dataLabelForPlot:(nonnull CPTPlot *)plot recordIndex:(NSUI
154154
whiteText.fontSize = self.titleSize * CPTFloat(0.5);
155155
});
156156

157-
newLayer = [[CPTTextLayer alloc] initWithText:[NSString stringWithFormat:@"%.0f", [self.plotData[index] doubleValue]] style:whiteText];
157+
newLayer = [[CPTTextLayer alloc] initWithText:[NSString stringWithFormat:@"%.0f", (self.plotData[index]).doubleValue] style:whiteText];
158158
newLayer.fill = [CPTFill fillWithColor:[CPTColor darkGrayColor]];
159159
newLayer.cornerRadius = 5.0;
160160
newLayer.paddingLeft = 3.0;

‎examples/CorePlotGallery/src/plots/FunctionPlot.m‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,15 +212,15 @@ -(nullable UIFont *)italicFontForFont:(nonnull UIFont *)oldFont
212212
CPTStringArray fontNames = [UIFont fontNamesForFamilyName:oldFont.familyName];
213213

214214
for ( NSString *fontName in fontNames ) {
215-
NSString *upperCaseFontName = [fontName uppercaseString];
215+
NSString *upperCaseFontName = fontName.uppercaseString;
216216
if ( [upperCaseFontName rangeOfString:@"ITALIC"].location != NSNotFound ) {
217217
italicName = fontName;
218218
break;
219219
}
220220
}
221221
if ( !italicName ) {
222222
for ( NSString *fontName in fontNames ) {
223-
NSString *upperCaseFontName = [fontName uppercaseString];
223+
NSString *upperCaseFontName = fontName.uppercaseString;
224224
if ( [upperCaseFontName rangeOfString:@"OBLIQUE"].location != NSNotFound ) {
225225
italicName = fontName;
226226
break;

0 commit comments

Comments
 (0)