diff --git a/Charts/Charts.xcodeproj/project.pbxproj b/Charts/Charts.xcodeproj/project.pbxproj index 59c9699afd..6176f4c54b 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 1e2be05b6c..3af5a6e557 100755 --- a/Charts/Classes/Charts/ChartViewBase.swift +++ b/Charts/Classes/Charts/ChartViewBase.swift @@ -357,7 +357,7 @@ open 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 f2ff57876e..285f739fb5 100755 --- a/Charts/Classes/Charts/PieRadarChartViewBase.swift +++ b/Charts/Classes/Charts/PieRadarChartViewBase.swift @@ -627,7 +627,7 @@ open class PieRadarChartViewBase: ChartViewBase #endif #if os(OSX) - open override func mouseDown(_ theEvent: NSEvent) + open override func mouseDown(with theEvent: NSEvent) { // if rotation by touch is enabled if rotationEnabled @@ -641,11 +641,11 @@ open class PieRadarChartViewBase: ChartViewBase if !_isRotating { - super.mouseDown(theEvent) + super.mouseDown(with: theEvent) } } - - open override func mouseDragged(_ theEvent: NSEvent) + + open override func mouseDragged(with theEvent: NSEvent) { if rotationEnabled { @@ -656,15 +656,15 @@ open class PieRadarChartViewBase: ChartViewBase if !_isRotating { - super.mouseDragged(theEvent) + super.mouseDragged(with: theEvent) } } - - open override func mouseUp(_ theEvent: NSEvent) + + open 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 28aa8bcda2..a8ad8c8bef 100644 --- a/Charts/Classes/Data/Implementations/Standard/ChartDataEntry.swift +++ b/Charts/Classes/Data/Implementations/Standard/ChartDataEntry.swift @@ -51,14 +51,14 @@ open class ChartDataEntry: NSObject open 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 @@ open 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/ChartHighlight.swift b/Charts/Classes/Highlight/ChartHighlight.swift index 99a9a37eb1..02e363203d 100644 --- a/Charts/Classes/Highlight/ChartHighlight.swift +++ b/Charts/Classes/Highlight/ChartHighlight.swift @@ -122,40 +122,39 @@ open class ChartHighlight: NSObject open 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/Utils/ChartPlatform.swift b/Charts/Classes/Utils/ChartPlatform.swift index 7876c9f90d..dca976e257 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. */ open 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 { @@ -375,7 +387,7 @@ types are aliased to either their UI* implementation (on iOS) or their NS* imple open class NSUIView: NSView { - open final override var isFlipped: Bool + open override var isFlipped: Bool { return true } @@ -385,17 +397,17 @@ types are aliased to either their UI* implementation (on iOS) or their NS* imple self.setNeedsDisplay(self.bounds) } - open final override func touchesBegan(with event: NSEvent) + open override func touchesBegan(with event: NSEvent) { self.nsuiTouchesBegan(event.touches(matching: .any, in: self), with: event) } - open final override func touchesEnded(with event: NSEvent) + open override func touchesEnded(with event: NSEvent) { self.nsuiTouchesEnded(event.touches(matching: .any, in: self), with: event) } - open final override func touchesMoved(with event: NSEvent) + open override func touchesMoved(with event: NSEvent) { self.nsuiTouchesMoved(event.touches(matching: .any, in: self), with: event) } @@ -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 09c78e85f7..77bb854fc0 100644 --- a/Charts/Classes/Utils/ChartSelectionDetail.swift +++ b/Charts/Classes/Utils/ChartSelectionDetail.swift @@ -77,30 +77,29 @@ open class ChartSelectionDetail: NSObject open 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 }