diff --git a/Charts/Charts.xcodeproj/project.pbxproj b/Charts/Charts.xcodeproj/project.pbxproj index 751ef01dd1..ee938fd631 100644 --- a/Charts/Charts.xcodeproj/project.pbxproj +++ b/Charts/Charts.xcodeproj/project.pbxproj @@ -1486,6 +1486,7 @@ ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 3.0; TARGETED_DEVICE_FAMILY = "1,2"; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; @@ -1527,6 +1528,7 @@ IPHONEOS_DEPLOYMENT_TARGET = 8.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; + SWIFT_VERSION = 3.0; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; VERSIONING_SYSTEM = "apple-generic"; diff --git a/Charts/Classes/Charts/ChartViewBase.swift b/Charts/Classes/Charts/ChartViewBase.swift index 8e67765d94..c4af33f4dd 100755 --- a/Charts/Classes/Charts/ChartViewBase.swift +++ b/Charts/Classes/Charts/ChartViewBase.swift @@ -357,7 +357,7 @@ public class ChartViewBase: NSUIView, ChartDataProvider, ChartAnimatorDelegate // 23 is the smallest recommended font size on the TV font = NSUIFont.systemFont(ofSize: 23, weight: UIFontWeightMedium) #else - font = NSUIFont.systemFont(ofSize: NSUIFont.systemFontSize) + font = NSUIFont.systemFont(ofSize: NSUIFont.nsuiSystemFontSize) #endif } diff --git a/Charts/Classes/Charts/PieRadarChartViewBase.swift b/Charts/Classes/Charts/PieRadarChartViewBase.swift index 6d5fd7a82c..131c0958b8 100755 --- a/Charts/Classes/Charts/PieRadarChartViewBase.swift +++ b/Charts/Classes/Charts/PieRadarChartViewBase.swift @@ -627,7 +627,7 @@ public class PieRadarChartViewBase: ChartViewBase #endif #if os(OSX) - public override func mouseDown(_ theEvent: NSEvent) + public override func mouseDown(with theEvent: NSEvent) { // if rotation by touch is enabled if rotationEnabled @@ -641,11 +641,11 @@ public class PieRadarChartViewBase: ChartViewBase if !_isRotating { - super.mouseDown(theEvent) + super.mouseDown(with: theEvent) } } - public override func mouseDragged(_ theEvent: NSEvent) + public override func mouseDragged(with theEvent: NSEvent) { if rotationEnabled { @@ -656,15 +656,15 @@ public class PieRadarChartViewBase: ChartViewBase if !_isRotating { - super.mouseDragged(theEvent) + super.mouseDragged(with: theEvent) } } - public override func mouseUp(_ theEvent: NSEvent) + public override func mouseUp(with theEvent: NSEvent) { if !_isRotating { - super.mouseUp(theEvent) + super.mouseUp(with: theEvent) } if rotationEnabled diff --git a/Charts/Classes/Data/Implementations/Standard/ChartDataEntry.swift b/Charts/Classes/Data/Implementations/Standard/ChartDataEntry.swift index 7a105b81cf..9a60a16f5a 100644 --- a/Charts/Classes/Data/Implementations/Standard/ChartDataEntry.swift +++ b/Charts/Classes/Data/Implementations/Standard/ChartDataEntry.swift @@ -51,14 +51,14 @@ public class ChartDataEntry: NSObject public override func isEqual(_ object: Any?) -> Bool { - let object = object as? AnyObject - - if (object === nil) - { - return false - } - - if (!object!.isKind(of: type(of: self))) + if (object == nil) + { + return false + } + + let object = object as AnyObject + + if (!object.isKind(of: type(of: self))) { return false } @@ -68,12 +68,12 @@ public class ChartDataEntry: NSObject return false } - if (object!.xIndex != xIndex) + if (object.xIndex != xIndex) { return false } - if (fabs(object!.value - value) > 0.00001) + if (fabs(object.value - value) > 0.00001) { return false } diff --git a/Charts/Classes/Highlight/BarChartHighlighter.swift b/Charts/Classes/Highlight/BarChartHighlighter.swift index 3b007e1365..29814d3988 100644 --- a/Charts/Classes/Highlight/BarChartHighlighter.swift +++ b/Charts/Classes/Highlight/BarChartHighlighter.swift @@ -198,7 +198,7 @@ public class BarChartHighlighter: ChartHighlighter self.chart?.getTransformer(ChartYAxis.AxisDependency.left).pixelToValue(&pt) let xVal = Double(pt.x) - let setCount = barData.dataSetCount ?? 0 + let setCount = barData.dataSetCount // calculate how often the group-space appears let steps = Int(xVal / (Double(setCount) + Double(barData.groupSpace))) diff --git a/Charts/Classes/Highlight/ChartHighlight.swift b/Charts/Classes/Highlight/ChartHighlight.swift index 23dab174a2..0569291588 100644 --- a/Charts/Classes/Highlight/ChartHighlight.swift +++ b/Charts/Classes/Highlight/ChartHighlight.swift @@ -122,40 +122,39 @@ public class ChartHighlight: NSObject public override func isEqual(_ object: Any?) -> Bool { - - let object = object as? AnyObject - - if (object === nil) + if (object == nil) { return false } + + let object = object as AnyObject - if (!object!.isKind(of: type(of: self))) + if (!object.isKind(of: type(of: self))) { return false } - if (object!.xIndex != _xIndex) + if (object.xIndex != _xIndex) { return false } - if (object!.dataIndex != dataIndex) + if (object.dataIndex != dataIndex) { return false } - if (object!.dataSetIndex != _dataSetIndex) + if (object.dataSetIndex != _dataSetIndex) { return false } - if (object!.stackIndex != _stackIndex) + if (object.stackIndex != _stackIndex) { return false } - if (object!.value != value) + if (object.value != value) { return false } diff --git a/Charts/Classes/Highlight/HorizontalBarChartHighlighter.swift b/Charts/Classes/Highlight/HorizontalBarChartHighlighter.swift index 2243014ffd..07fc1f72f4 100644 --- a/Charts/Classes/Highlight/HorizontalBarChartHighlighter.swift +++ b/Charts/Classes/Highlight/HorizontalBarChartHighlighter.swift @@ -93,7 +93,7 @@ public class HorizontalBarChartHighlighter: BarChartHighlighter self.chart?.getTransformer(ChartYAxis.AxisDependency.left).pixelToValue(&pt) let yVal = Double(pt.y) - let setCount = barData.dataSetCount ?? 0 + let setCount = barData.dataSetCount // calculate how often the group-space appears let steps = Int(yVal / (Double(setCount) + Double(barData.groupSpace))) diff --git a/Charts/Classes/Renderers/LineChartRenderer.swift b/Charts/Classes/Renderers/LineChartRenderer.swift index 5c4c177ca4..4242a1a9ca 100644 --- a/Charts/Classes/Renderers/LineChartRenderer.swift +++ b/Charts/Classes/Renderers/LineChartRenderer.swift @@ -115,7 +115,7 @@ public class LineChartRenderer: LineRadarChartRenderer // the path for the cubic-spline let cubicPath = CGMutablePath() - var valueToPixelMatrix = trans.valueToPixelMatrix + let valueToPixelMatrix = trans.valueToPixelMatrix let size = Int(ceil(CGFloat(maxx - minx) * phaseX + CGFloat(minx))) @@ -197,7 +197,7 @@ public class LineChartRenderer: LineRadarChartRenderer // the path for the cubic-spline let cubicPath = CGMutablePath() - var valueToPixelMatrix = trans.valueToPixelMatrix + let valueToPixelMatrix = trans.valueToPixelMatrix let size = Int(ceil(CGFloat(maxx - minx) * phaseX + CGFloat(minx))) @@ -475,7 +475,7 @@ public class LineChartRenderer: LineRadarChartRenderer let phaseX = max(0.0, min(1.0, animator?.phaseX ?? 1.0)) let phaseY = animator?.phaseY ?? 1.0 let drawSteppedEnabled = dataSet.mode == .stepped - var matrix = matrix + let matrix = matrix var e: ChartDataEntry! diff --git a/Charts/Classes/Utils/ChartPlatform.swift b/Charts/Classes/Utils/ChartPlatform.swift index 0ad387e6fe..fcffe008db 100644 --- a/Charts/Classes/Utils/ChartPlatform.swift +++ b/Charts/Classes/Utils/ChartPlatform.swift @@ -200,6 +200,12 @@ types are aliased to either their UI* implementation (on iOS) or their NS* imple UIGraphicsBeginImageContextWithOptions(size, opaque, scale) } + extension NSUIFont { + static var nsuiSystemFontSize: CGFloat { + return NSUIFont.systemFontSize + } + } + #endif #if os(OSX) @@ -221,6 +227,12 @@ types are aliased to either their UI* implementation (on iOS) or their NS* imple public typealias NSUIRotationGestureRecognizer = NSRotationGestureRecognizer public typealias NSUIScreen = NSScreen + extension NSUIFont { + static var nsuiSystemFontSize: CGFloat { + return NSUIFont.systemFontSize() + } + } + /** On OS X there is no CADisplayLink. Use a 60 fps timer to render the animations. */ public class NSUIDisplayLink { @@ -251,7 +263,7 @@ types are aliased to either their UI* implementation (on iOS) or their NS* imple _self._target?.performSelector(onMainThread: _self._selector, with: _self, waitUntilDone: false) return kCVReturnSuccess - }, UnsafeMutablePointer(unsafeAddress(of: self))) + }, Unmanaged.passUnretained(self).toOpaque()) } else { @@ -503,9 +515,8 @@ types are aliased to either their UI* implementation (on iOS) or their NS* imple func NSUIGraphicsPushContext(_ context: CGContext) { - let address = unsafeAddress(of: context) - let ptr: UnsafeMutablePointer = UnsafeMutablePointer(UnsafePointer(address)) - let cx = NSGraphicsContext(graphicsPort: ptr, flipped: true) + let address = Unmanaged.passUnretained(context).toOpaque() + let cx = NSGraphicsContext(graphicsPort: address, flipped: true) NSGraphicsContext.saveGraphicsState() NSGraphicsContext.setCurrent(cx) } @@ -550,8 +561,8 @@ types are aliased to either their UI* implementation (on iOS) or their NS* imple let colorSpace = CGColorSpaceCreateDeviceRGB() let ctx = CGContext(data: nil, width: width, height: height, bitsPerComponent: 8, bytesPerRow: 4*width, space: colorSpace, bitmapInfo: (opaque ? CGImageAlphaInfo.noneSkipFirst.rawValue : CGImageAlphaInfo.premultipliedFirst.rawValue)) - ctx?.concatCTM(CGAffineTransform(a: 1, b: 0, c: 0, d: -1, tx: 0, ty: CGFloat(height))) - ctx?.scale(x: scale, y: scale) + ctx?.concatenate(CGAffineTransform(a: 1, b: 0, c: 0, d: -1, tx: 0, ty: CGFloat(height))) + ctx?.scaleBy(x: scale, y: scale) NSUIGraphicsPushContext(ctx!) } } @@ -586,6 +597,13 @@ types are aliased to either their UI* implementation (on iOS) or their NS* imple return NSUIScreen.main() } + extension NSParagraphStyle { + // This, oddly, is different on iOS (default is a static function on OS X) + static var `default`: NSParagraphStyle { + return NSParagraphStyle.default() + } + } + extension NSString { /** On OS X, only size(withAttributes:) exists. It is expected that OSX will catch up and also change to size(attributes:). For now, use this as proxy. */ diff --git a/Charts/Classes/Utils/ChartSelectionDetail.swift b/Charts/Classes/Utils/ChartSelectionDetail.swift index 253d572e25..d3d59f9083 100644 --- a/Charts/Classes/Utils/ChartSelectionDetail.swift +++ b/Charts/Classes/Utils/ChartSelectionDetail.swift @@ -77,30 +77,29 @@ public class ChartSelectionDetail: NSObject public override func isEqual(_ object: Any?) -> Bool { - - let object = object as? AnyObject - - if (object === nil) + if (object == nil) { return false } + + let object = object as AnyObject - if (!object!.isKind(of: type(of: self))) + if (!object.isKind(of: type(of: self))) { return false } - if (object!.value != _value) + if (object.value != _value) { return false } - if (object!.dataSetIndex != _dataSetIndex) + if (object.dataSetIndex != _dataSetIndex) { return false } - if (object!.dataSet !== _dataSet) + if (object.dataSet !== _dataSet) { return false } diff --git a/Charts/Classes/Utils/ChartUtils.swift b/Charts/Classes/Utils/ChartUtils.swift index db44c3e88b..670402ad0a 100755 --- a/Charts/Classes/Utils/ChartUtils.swift +++ b/Charts/Classes/Utils/ChartUtils.swift @@ -394,7 +394,7 @@ public class ChartUtils } else { - newArray.append(val as! NSObject) + newArray.append(NSString(string: val!)) } } return newArray