Skip to content

Commit

Permalink
Conforms to Swift 3 - Xcode 8 beta 6
Browse files Browse the repository at this point in the history
  • Loading branch information
acegreen committed Aug 20, 2016
1 parent c4c6e85 commit bd8dd48
Show file tree
Hide file tree
Showing 52 changed files with 415 additions and 493 deletions.
2 changes: 1 addition & 1 deletion Charts/Classes/Animation/ChartAnimationEasing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public enum ChartEasingOption: Int
case easeInOutBounce
}

public typealias ChartEasingFunctionBlock = ((elapsed: TimeInterval, duration: TimeInterval) -> CGFloat)
public typealias ChartEasingFunctionBlock = ((_ elapsed: TimeInterval, _ duration: TimeInterval) -> CGFloat)

internal func easingFunctionFromOption(_ easing: ChartEasingOption) -> ChartEasingFunctionBlock
{
Expand Down
12 changes: 6 additions & 6 deletions Charts/Classes/Animation/ChartAnimator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public class ChartAnimator: NSObject
{
if (_displayLink != nil)
{
_displayLink.remove(from: RunLoop.main, forMode: RunLoopMode(rawValue: RunLoopMode.commonModes.rawValue))
_displayLink.remove(from: RunLoop.main, forMode: RunLoopMode.commonModes)
_displayLink = nil

_enabledX = false
Expand Down Expand Up @@ -118,7 +118,7 @@ public class ChartAnimator: NSObject

if (_easingX != nil)
{
phaseX = _easingX!(elapsed: elapsed, duration: duration)
phaseX = _easingX!(elapsed, duration)
}
else
{
Expand All @@ -137,7 +137,7 @@ public class ChartAnimator: NSObject

if (_easingY != nil)
{
phaseY = _easingY!(elapsed: elapsed, duration: duration)
phaseY = _easingY!(elapsed, duration)
}
else
{
Expand Down Expand Up @@ -196,7 +196,7 @@ public class ChartAnimator: NSObject
if (_enabledX || _enabledY)
{
_displayLink = NSUIDisplayLink(target: self, selector: #selector(ChartAnimator.animationLoop))
_displayLink.add(to: RunLoop.main, forMode: RunLoopMode(rawValue: RunLoopMode.commonModes.rawValue))
_displayLink.add(to: RunLoop.main, forMode: RunLoopMode.commonModes)
}
}

Expand Down Expand Up @@ -262,7 +262,7 @@ public class ChartAnimator: NSObject
if _displayLink === nil
{
_displayLink = NSUIDisplayLink(target: self, selector: #selector(ChartAnimator.animationLoop))
_displayLink.add(to: RunLoop.main, forMode: RunLoopMode(rawValue: RunLoopMode.commonModes.rawValue))
_displayLink.add(to: RunLoop.main, forMode: RunLoopMode.commonModes)
}
}
}
Expand Down Expand Up @@ -306,7 +306,7 @@ public class ChartAnimator: NSObject
if _displayLink === nil
{
_displayLink = NSUIDisplayLink(target: self, selector: #selector(ChartAnimator.animationLoop))
_displayLink.add(to: RunLoop.main, forMode: RunLoopMode(rawValue: RunLoopMode.commonModes.rawValue))
_displayLink.add(to: RunLoop.main, forMode: RunLoopMode.commonModes)
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions Charts/Classes/Charts/BarLineChartViewBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChar
#endif
}

public override func observeValue(forKeyPath keyPath: String?, of object: AnyObject?, change: [NSKeyValueChangeKey : AnyObject]?, context: UnsafeMutablePointer<Void>?)
public override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?)
{
// Saving current position of chart.
var oldPoint: CGPoint?
Expand All @@ -148,7 +148,7 @@ public class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChar
super.observeValue(forKeyPath: keyPath, of: object, change: change, context: context)

// Restoring old position of chart
if var newPoint = oldPoint where keepPositionOnRotation
if var newPoint = oldPoint, keepPositionOnRotation
{
getTransformer(.left).pointValueToPixel(&newPoint)
viewPortHandler.centerViewPort(pt: newPoint, chart: self)
Expand Down Expand Up @@ -824,7 +824,7 @@ public class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChar
_decelerationVelocity = recognizer.velocity(in: self)

_decelerationDisplayLink = NSUIDisplayLink(target: self, selector: #selector(BarLineChartViewBase.decelerationLoop))
_decelerationDisplayLink.add(to: RunLoop.main, forMode: RunLoopMode(rawValue: RunLoopMode.commonModes.rawValue))
_decelerationDisplayLink.add(to: RunLoop.main, forMode: RunLoopMode.commonModes)
}

_isDragging = false
Expand Down Expand Up @@ -875,7 +875,7 @@ public class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChar
{
if (_decelerationDisplayLink !== nil)
{
_decelerationDisplayLink.remove(from: RunLoop.main, forMode: RunLoopMode(rawValue: RunLoopMode.commonModes.rawValue))
_decelerationDisplayLink.remove(from: RunLoop.main, forMode: RunLoopMode.commonModes)
_decelerationDisplayLink = nil
}
}
Expand Down Expand Up @@ -981,7 +981,7 @@ public class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChar

// If there is two scrollview together, we pick the superview of the inner scrollview.
// In the case of UITableViewWrepperView, the superview will be UITableView
if let superViewOfScrollView = scrollView?.superview where superViewOfScrollView is NSUIScrollView
if let superViewOfScrollView = scrollView?.superview, superViewOfScrollView is NSUIScrollView
{
scrollView = superViewOfScrollView
}
Expand Down
13 changes: 6 additions & 7 deletions Charts/Classes/Charts/ChartViewBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ public class ChartViewBase: NSUIView, ChartDataProvider, ChartAnimatorDelegate
// check if a custom formatter is set or not
var reference = Double(0.0)

if let data = _data where data.xValCount >= 2
if let data = _data, data.xValCount >= 2
{
reference = fabs(max - min)
}
Expand Down Expand Up @@ -300,9 +300,8 @@ public class ChartViewBase: NSUIView, ChartDataProvider, ChartAnimatorDelegate
defer { context.restoreGState() }

let hasText = noDataText.characters.count > 0
let hasDescription = noDataTextDescription?.characters.count > 0
var textHeight = hasText ? infoFont.lineHeight : 0.0
if hasDescription
if let hasDescription = noDataTextDescription?.characters, hasDescription.count > 0
{
textHeight += infoFont.lineHeight
}
Expand Down Expand Up @@ -768,7 +767,7 @@ public class ChartViewBase: NSUIView, ChartDataProvider, ChartAnimatorDelegate
/// - returns: the x-value at the given index
public func getXValue(_ index: Int) -> String!
{
guard let data = _data where data.xValCount > index else
guard let data = _data, data.xValCount > index else
{
return nil
}
Expand Down Expand Up @@ -850,7 +849,7 @@ public class ChartViewBase: NSUIView, ChartDataProvider, ChartAnimatorDelegate
public func saveToPath(_ path: String, format: ImageFormat, compressionQuality: Double) throws -> Bool
{
if let image = getChartImage(transparent: format != .jpeg) {
var imageData: NSData?
var imageData: Data?
switch (format)
{
case .png:
Expand Down Expand Up @@ -882,15 +881,15 @@ public class ChartViewBase: NSUIView, ChartDataProvider, ChartAnimatorDelegate

internal var _viewportJobs = [ChartViewPortJob]()

public override func observeValue(forKeyPath keyPath: String?, of object: AnyObject?, change: [NSKeyValueChangeKey : AnyObject]?, context: UnsafeMutablePointer<Void>?)
public override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?)
{
if (keyPath == "bounds" || keyPath == "frame")
{
let bounds = self.bounds

if (_viewPortHandler !== nil &&
(bounds.size.width != _viewPortHandler.chartWidth ||
bounds.size.height != _viewPortHandler.chartHeight))
bounds.size.height != _viewPortHandler.chartHeight))
{
_viewPortHandler.setChartDimens(width: bounds.size.width, height: bounds.size.height)

Expand Down
2 changes: 1 addition & 1 deletion Charts/Classes/Charts/CombinedChartView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public class CombinedChartView: BarLineChartViewBase, LineChartDataProvider, Bar

_xAxis.axisRange = abs(_xAxis._axisMaximum - _xAxis._axisMinimum)

if _xAxis.axisRange == 0.0 && self.lineData?.yValCount > 0
if _xAxis.axisRange == 0.0, let lineData = self.lineData, lineData.yValCount > 0
{
_xAxis.axisRange = 1.0
}
Expand Down
8 changes: 4 additions & 4 deletions Charts/Classes/Charts/PieRadarChartViewBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public class PieRadarChartViewBase: ChartViewBase
{
calcMinMax()

if let data = _data where _legend !== nil
if let data = _data, _legend !== nil
{
_legendRenderer.computeLegend(data)
}
Expand Down Expand Up @@ -543,7 +543,7 @@ public class PieRadarChartViewBase: ChartViewBase
{
_decelerationLastTime = CACurrentMediaTime()
_decelerationDisplayLink = NSUIDisplayLink(target: self, selector: #selector(PieRadarChartViewBase.decelerationLoop))
_decelerationDisplayLink.add(to: RunLoop.main, forMode: RunLoopMode(rawValue: RunLoopMode.commonModes.rawValue))
_decelerationDisplayLink.add(to: RunLoop.main, forMode: RunLoopMode.commonModes)
}
}
}
Expand Down Expand Up @@ -788,7 +788,7 @@ public class PieRadarChartViewBase: ChartViewBase
{
if (_decelerationDisplayLink !== nil)
{
_decelerationDisplayLink.remove(from: RunLoop.main, forMode: RunLoopMode(rawValue: RunLoopMode.commonModes.rawValue))
_decelerationDisplayLink.remove(from: RunLoop.main, forMode: RunLoopMode.commonModes)
_decelerationDisplayLink = nil
}
}
Expand Down Expand Up @@ -944,7 +944,7 @@ public class PieRadarChartViewBase: ChartViewBase
{
_decelerationLastTime = CACurrentMediaTime()
_decelerationDisplayLink = NSUIDisplayLink(target: self, selector: #selector(PieRadarChartViewBase.decelerationLoop))
_decelerationDisplayLink.add(to: RunLoop.main, forMode: RunLoopMode(rawValue: RunLoopMode.commonModes.rawValue))
_decelerationDisplayLink.add(to: RunLoop.main, forMode: RunLoopMode.commonModes)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Charts/Classes/Charts/RadarChartView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public class RadarChartView: PieRadarChartViewBase
_yAxisRenderer?.computeAxis(yMin: _yAxis._axisMinimum, yMax: _yAxis._axisMaximum)
_xAxisRenderer?.computeAxis(xValAverageLength: data?.xValAverageLength ?? 0, xValues: data?.xVals ?? [])

if let data = _data, legend = _legend where !legend.isLegendCustom
if let data = _data, let legend = _legend, !legend.isLegendCustom
{
_legendRenderer?.computeLegend(data)
}
Expand Down
2 changes: 1 addition & 1 deletion Charts/Classes/Components/ChartYAxis.swift
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ public class ChartYAxis: ChartAxisBase
return ""
}

return (valueFormatter ?? _defaultValueFormatter).string(from: entries[index])!
return (valueFormatter ?? _defaultValueFormatter).string(for: entries[index])!
}

/// - returns: true if this axis needs horizontal offset, false if no offset is needed.
Expand Down
6 changes: 3 additions & 3 deletions Charts/Classes/Data/Implementations/ChartBaseDataSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ public class ChartBaseDataSet: NSObject, IChartDataSet

public override var description: String
{
return String(format: "%@, label: %@, %i entries", arguments: [NSStringFromClass(self.dynamicType), self.label ?? "", self.entryCount])
return String(format: "%@, label: %@, %i entries", arguments: [NSStringFromClass(type(of: self)), self.label ?? "", self.entryCount])
}

public override var debugDescription: String
Expand All @@ -314,9 +314,9 @@ public class ChartBaseDataSet: NSObject, IChartDataSet

// MARK: - NSCopying

public func copyWithZone(_ zone: NSZone?) -> AnyObject
public func copyWithZone(_ zone: NSZone?) -> Any
{
let copy = self.dynamicType.init()
let copy = type(of: self).init()

copy.colors = colors
copy.valueColors = valueColors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class BarChartDataEntry: ChartDataEntry
}

/// Constructor for normal bars (not stacked).
public override init(value: Double, xIndex: Int, data: AnyObject?)
public override init(value: Double, xIndex: Int, data: Any?)
{
super.init(value: value, xIndex: xIndex, data: data)
}
Expand Down Expand Up @@ -134,7 +134,7 @@ public class BarChartDataEntry: ChartDataEntry

// MARK: NSCopying

public override func copyWithZone(_ zone: NSZone?) -> AnyObject
public override func copyWithZone(_ zone: NSZone?) -> Any
{
let copy = super.copyWithZone(zone) as! BarChartDataEntry
copy._values = _values
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public class BarChartDataSet: BarLineScatterCandleBubbleChartDataSet, IBarChartD

// MARK: - NSCopying

public override func copyWithZone(_ zone: NSZone?) -> AnyObject
public override func copyWithZone(_ zone: NSZone?) -> Any
{
let copy = super.copyWithZone(zone) as! BarChartDataSet
copy._stackSize = _stackSize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class BarLineScatterCandleBubbleChartDataSet: ChartDataSet, IBarLineScatt

// MARK: - NSCopying

public override func copyWithZone(_ zone: NSZone?) -> AnyObject
public override func copyWithZone(_ zone: NSZone?) -> Any
{
let copy = super.copyWithZone(zone) as! BarLineScatterCandleBubbleChartDataSet
copy.highlightColor = highlightColor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class BubbleChartDataEntry: ChartDataEntry

// MARK: NSCopying

public override func copyWithZone(_ zone: NSZone?) -> AnyObject
public override func copyWithZone(_ zone: NSZone?) -> Any
{
let copy = super.copyWithZone(zone) as! BubbleChartDataEntry
copy.size = size
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public class BubbleChartDataSet: BarLineScatterCandleBubbleChartDataSet, IBubble

// MARK: - NSCopying

public override func copyWithZone(_ zone: NSZone?) -> AnyObject
public override func copyWithZone(_ zone: NSZone?) -> Any
{
let copy = super.copyWithZone(zone) as! BubbleChartDataSet
copy._xMin = _xMin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public class CandleChartDataEntry: ChartDataEntry

// MARK: NSCopying

public override func copyWithZone(_ zone: NSZone?) -> AnyObject
public override func copyWithZone(_ zone: NSZone?) -> Any
{
let copy = super.copyWithZone(zone) as! CandleChartDataEntry
copy.high = high
Expand Down
18 changes: 10 additions & 8 deletions Charts/Classes/Data/Implementations/Standard/ChartDataEntry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,30 +38,32 @@ public class ChartDataEntry: NSObject
self.xIndex = xIndex
}

public init(value: Double, xIndex: Int, data: AnyObject?)
public init(value: Double, xIndex: Int, data: Any?)
{
super.init()

self.value = value
self.xIndex = xIndex
self.data = data
self.data = data as AnyObject
}

// MARK: NSObject

public override func isEqual(_ object: AnyObject?) -> Bool
public override func isEqual(_ object: Any?) -> Bool
{
let object = object as? AnyObject

if (object === nil)
{
return false
}

if (!object!.isKind(of: self.dynamicType))
if (!object!.isKind(of: type(of: self)))
{
return false
}

if let d = object as? ChartDataEntry where d.data !== self.data || !d.isEqual(self.data)
if let d = object as? ChartDataEntry, d.data !== self.data || !d.isEqual(self.data)
{
return false
}
Expand All @@ -88,9 +90,9 @@ public class ChartDataEntry: NSObject

// MARK: NSCopying

public func copyWithZone(_ zone: NSZone?) -> AnyObject
public func copyWithZone(_ zone: NSZone?) -> Any
{
let copy = self.dynamicType.init()
let copy = type(of: self).init()

copy.value = value
copy.xIndex = xIndex
Expand All @@ -107,7 +109,7 @@ public func ==(lhs: ChartDataEntry, rhs: ChartDataEntry) -> Bool
return true
}

if (!lhs.isKind(of: rhs.dynamicType))
if (!lhs.isKind(of: type(of: rhs)))
{
return false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ public class ChartDataSet: ChartBaseDataSet
}
}

if _yVals.last?.xIndex > e.xIndex
if let xIndex = _yVals.last?.xIndex, xIndex > e.xIndex
{
var closestIndex = entryIndex(xIndex: e.xIndex, rounding: .closest)
if _yVals[closestIndex].xIndex < e.xIndex
Expand Down Expand Up @@ -501,7 +501,7 @@ public class ChartDataSet: ChartBaseDataSet

// MARK: - NSCopying

public override func copyWithZone(_ zone: NSZone?) -> AnyObject
public override func copyWithZone(_ zone: NSZone?) -> Any
{
let copy = super.copyWithZone(zone) as! ChartDataSet

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public class LineChartDataSet: LineRadarChartDataSet, ILineChartDataSet

// MARK: NSCopying

public override func copyWithZone(_ zone: NSZone?) -> AnyObject
public override func copyWithZone(_ zone: NSZone?) -> Any
{
let copy = super.copyWithZone(zone) as! LineChartDataSet
copy.circleColors = circleColors
Expand Down
Loading

0 comments on commit bd8dd48

Please sign in to comment.