Skip to content

Commit

Permalink
Merge pull request #1342 from acegreen/Swift-3.0
Browse files Browse the repository at this point in the history
Conforms to Swift 3 - Xcode 8 beta 6
  • Loading branch information
liuxuan30 authored Aug 30, 2016
2 parents 33e1783 + d2daccc commit a3c03c2
Show file tree
Hide file tree
Showing 55 changed files with 405 additions and 488 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
4 changes: 2 additions & 2 deletions Charts/Classes/Animation/ChartAnimator.swift
Original file line number Diff line number Diff line change
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
3 changes: 1 addition & 2 deletions Charts/Classes/Charts/BarChartView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ public class BarChartView: BarLineChartViewBase, BarChartDataProvider
/// - returns: the bounding box of the specified Entry in the specified DataSet. Returns null if the Entry could not be found in the charts data.
public func getBarBounds(_ e: BarChartDataEntry) -> CGRect
{
guard let
set = _data?.getDataSetForEntry(e) as? IBarChartDataSet
guard let set = _data?.getDataSetForEntry(e) as? IBarChartDataSet
else { return CGRect.null }

let barspace = set.barSpace
Expand Down
9 changes: 4 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 @@ -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 Expand Up @@ -1895,8 +1895,7 @@ public class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChar

getTransformer(.left).pixelToValue(&pt)

guard let
data = _data
guard let data = _data
else { return Int(round(pt.x)) }

return min(data.xValCount - 1, Int(floor(pt.x)))
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
2 changes: 1 addition & 1 deletion 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
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(from: entries[index] as NSNumber)!
}

/// - 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
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public class LineRadarChartDataSet: LineScatterCandleRadarChartDataSet, ILineRad

// MARK: NSCopying

public override func copyWithZone(_ zone: NSZone?) -> AnyObject
public override func copyWithZone(_ zone: NSZone?) -> Any
{
let copy = super.copyWithZone(zone) as! LineRadarChartDataSet
copy.fillColor = fillColor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class LineScatterCandleRadarChartDataSet: BarLineScatterCandleBubbleChart

// MARK: NSCopying

public override func copyWithZone(_ zone: NSZone?) -> AnyObject
public override func copyWithZone(_ zone: NSZone?) -> Any
{
let copy = super.copyWithZone(zone) as! LineScatterCandleRadarChartDataSet
copy.drawHorizontalHighlightIndicatorEnabled = drawHorizontalHighlightIndicatorEnabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public class PieChartDataSet: ChartDataSet, IPieChartDataSet

// MARK: - NSCopying

public override func copyWithZone(_ zone: NSZone?) -> AnyObject
public override func copyWithZone(_ zone: NSZone?) -> Any
{
let copy = super.copyWithZone(zone) as! PieChartDataSet
copy._sliceSpace = _sliceSpace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class ScatterChartDataSet: LineScatterCandleRadarChartDataSet, IScatterCh

// MARK: NSCopying

public override func copyWithZone(_ zone: NSZone?) -> AnyObject
public override func copyWithZone(_ zone: NSZone?) -> Any
{
let copy = super.copyWithZone(zone) as! ScatterChartDataSet
copy.scatterShapeSize = scatterShapeSize
Expand Down
6 changes: 2 additions & 4 deletions Charts/Classes/Highlight/BarChartHighlighter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ public class BarChartHighlighter: ChartHighlighter
guard let selectionDetail = getSelectionDetail(xIndex: xIndex, y: y, dataSetIndex: dataSetIndex)
else { return nil }

if let set = barData.getDataSetByIndex(dataSetIndex) as? IBarChartDataSet
where set.isStacked
if let set = barData.getDataSetByIndex(dataSetIndex) as? IBarChartDataSet, set.isStacked
{
var pt = CGPoint(x: 0.0, y: y)

Expand Down Expand Up @@ -139,8 +138,7 @@ public class BarChartHighlighter: ChartHighlighter
stackIndex: -1)
}

if let ranges = getRanges(entry: entry)
where ranges.count > 0
if let ranges = getRanges(entry: entry), ranges.count > 0
{
let stackIndex = getClosestStackIndex(ranges: ranges, value: yValue)
return ChartHighlight(xIndex: xIndex,
Expand Down
Loading

1 comment on commit a3c03c2

@eduardourso
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Please sign in to comment.