Skip to content

Commit 1b08577

Browse files
jjatieliuxuan30
authored andcommitted
Data as any (#3863)
* `ChartEntry.data` is now of type `Any` There is no need to restrict `ChartEntry.data` to `AnyObject`. This PR loosens that restriction. As a result we cannot compare `data`, though this should never have been the case in the first place. * Updated `ChartDataEntry` initializers to accept `Any` for `data` * Updated test
1 parent c6b4c67 commit 1b08577

File tree

8 files changed

+21
-23
lines changed

8 files changed

+21
-23
lines changed

Source/Charts/Data/Implementations/Standard/BarChartDataEntry.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ open class BarChartDataEntry: ChartDataEntry
3737
}
3838

3939
/// Constructor for normal bars (not stacked).
40-
public convenience init(x: Double, y: Double, data: AnyObject?)
40+
public convenience init(x: Double, y: Double, data: Any?)
4141
{
4242
self.init(x: x, y: y)
4343
self.data = data
@@ -51,7 +51,7 @@ open class BarChartDataEntry: ChartDataEntry
5151
}
5252

5353
/// Constructor for normal bars (not stacked).
54-
public convenience init(x: Double, y: Double, icon: NSUIImage?, data: AnyObject?)
54+
public convenience init(x: Double, y: Double, icon: NSUIImage?, data: Any?)
5555
{
5656
self.init(x: x, y: y)
5757
self.icon = icon
@@ -75,14 +75,14 @@ open class BarChartDataEntry: ChartDataEntry
7575
}
7676

7777
/// Constructor for stacked bar entries. One data object for whole stack
78-
@objc public convenience init(x: Double, yValues: [Double], data: AnyObject?)
78+
@objc public convenience init(x: Double, yValues: [Double], data: Any?)
7979
{
8080
self.init(x: x, yValues: yValues)
8181
self.data = data
8282
}
8383

8484
/// Constructor for stacked bar entries. One data object for whole stack
85-
@objc public convenience init(x: Double, yValues: [Double], icon: NSUIImage?, data: AnyObject?)
85+
@objc public convenience init(x: Double, yValues: [Double], icon: NSUIImage?, data: Any?)
8686
{
8787
self.init(x: x, yValues: yValues)
8888
self.icon = icon

Source/Charts/Data/Implementations/Standard/BubbleChartDataEntry.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ open class BubbleChartDataEntry: ChartDataEntry
3838
/// - y: The value on the y-axis.
3939
/// - size: The size of the bubble.
4040
/// - data: Spot for additional data this Entry represents.
41-
@objc public convenience init(x: Double, y: Double, size: CGFloat, data: AnyObject?)
41+
@objc public convenience init(x: Double, y: Double, size: CGFloat, data: Any?)
4242
{
4343
self.init(x: x, y: y, size: size)
4444
self.data = data
@@ -61,7 +61,7 @@ open class BubbleChartDataEntry: ChartDataEntry
6161
/// - size: The size of the bubble.
6262
/// - icon: icon image
6363
/// - data: Spot for additional data this Entry represents.
64-
@objc public convenience init(x: Double, y: Double, size: CGFloat, icon: NSUIImage?, data: AnyObject?)
64+
@objc public convenience init(x: Double, y: Double, size: CGFloat, icon: NSUIImage?, data: Any?)
6565
{
6666
self.init(x: x, y: y, size: size)
6767
self.icon = icon

Source/Charts/Data/Implementations/Standard/CandleChartDataEntry.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ open class CandleChartDataEntry: ChartDataEntry
4646
self.icon = icon
4747
}
4848

49-
@objc public convenience init(x: Double, shadowH: Double, shadowL: Double, open: Double, close: Double, data: AnyObject?)
49+
@objc public convenience init(x: Double, shadowH: Double, shadowL: Double, open: Double, close: Double, data: Any?)
5050
{
5151
self.init(x: x, shadowH: shadowH, shadowL: shadowL, open: open, close: close)
5252
self.data = data
5353
}
5454

55-
@objc public convenience init(x: Double, shadowH: Double, shadowL: Double, open: Double, close: Double, icon: NSUIImage?, data: AnyObject?)
55+
@objc public convenience init(x: Double, shadowH: Double, shadowL: Double, open: Double, close: Double, icon: NSUIImage?, data: Any?)
5656
{
5757
self.init(x: x, shadowH: shadowH, shadowL: shadowL, open: open, close: close)
5858
self.icon = icon

Source/Charts/Data/Implementations/Standard/ChartDataEntry.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ open class ChartDataEntry: ChartDataEntryBase, NSCopying
3939
/// - y: the y value (the actual value of the entry)
4040
/// - data: Space for additional data this Entry represents.
4141

42-
@objc public convenience init(x: Double, y: Double, data: AnyObject?)
42+
@objc public convenience init(x: Double, y: Double, data: Any?)
4343
{
4444
self.init(x: x, y: y)
4545
self.data = data
@@ -66,7 +66,7 @@ open class ChartDataEntry: ChartDataEntryBase, NSCopying
6666
/// - icon: icon image
6767
/// - data: Space for additional data this Entry represents.
6868

69-
@objc public convenience init(x: Double, y: Double, icon: NSUIImage?, data: AnyObject?)
69+
@objc public convenience init(x: Double, y: Double, icon: NSUIImage?, data: Any?)
7070
{
7171
self.init(x: x, y: y)
7272
self.icon = icon
@@ -104,8 +104,7 @@ extension ChartDataEntry/*: Equatable*/ {
104104
return true
105105
}
106106

107-
return ((data == nil && object.data == nil) || (data?.isEqual(object.data) ?? false))
108-
&& y == object.y
107+
return y == object.y
109108
&& x == object.x
110109
}
111110
}

Source/Charts/Data/Implementations/Standard/ChartDataEntryBase.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ open class ChartDataEntryBase: NSObject
1717
@objc open var y = 0.0
1818

1919
/// optional spot for additional data this Entry represents
20-
@objc open var data: AnyObject?
20+
@objc open var data: Any?
2121

2222
/// optional icon image
2323
@objc open var icon: NSUIImage?
@@ -42,7 +42,7 @@ open class ChartDataEntryBase: NSObject
4242
/// - y: the y value (the actual value of the entry)
4343
/// - data: Space for additional data this Entry represents.
4444

45-
@objc public convenience init(y: Double, data: AnyObject?)
45+
@objc public convenience init(y: Double, data: Any?)
4646
{
4747
self.init(y: y)
4848

@@ -65,7 +65,7 @@ open class ChartDataEntryBase: NSObject
6565
/// - icon: icon image
6666
/// - data: Space for additional data this Entry represents.
6767

68-
@objc public convenience init(y: Double, icon: NSUIImage?, data: AnyObject?)
68+
@objc public convenience init(y: Double, icon: NSUIImage?, data: Any?)
6969
{
7070
self.init(y: y)
7171

@@ -91,7 +91,6 @@ extension ChartDataEntryBase/*: Equatable*/ {
9191
return true
9292
}
9393

94-
return ((data == nil && object.data == nil) || (data?.isEqual(object.data) ?? false))
95-
&& y == object.y
94+
return y == object.y
9695
}
9796
}

Source/Charts/Data/Implementations/Standard/PieChartDataEntry.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ open class PieChartDataEntry: ChartDataEntry
4040
/// - value: The value on the y-axis
4141
/// - label: The label for the x-axis
4242
/// - data: Spot for additional data this Entry represents
43-
@objc public convenience init(value: Double, label: String?, data: AnyObject?)
43+
@objc public convenience init(value: Double, label: String?, data: Any?)
4444
{
4545
self.init(value: value, label: label, icon: nil, data: data)
4646
}
@@ -61,7 +61,7 @@ open class PieChartDataEntry: ChartDataEntry
6161
/// - label: The label for the x-axis
6262
/// - icon: icon image
6363
/// - data: Spot for additional data this Entry represents
64-
@objc public convenience init(value: Double, label: String?, icon: NSUIImage?, data: AnyObject?)
64+
@objc public convenience init(value: Double, label: String?, icon: NSUIImage?, data: Any?)
6565
{
6666
self.init(value: value)
6767
self.label = label
@@ -72,7 +72,7 @@ open class PieChartDataEntry: ChartDataEntry
7272
/// - Parameters:
7373
/// - value: The value on the y-axis
7474
/// - data: Spot for additional data this Entry represents
75-
@objc public convenience init(value: Double, data: AnyObject?)
75+
@objc public convenience init(value: Double, data: Any?)
7676
{
7777
self.init(value: value)
7878
self.data = data
@@ -91,7 +91,7 @@ open class PieChartDataEntry: ChartDataEntry
9191
/// - value: The value on the y-axis
9292
/// - icon: icon image
9393
/// - data: Spot for additional data this Entry represents
94-
@objc public convenience init(value: Double, icon: NSUIImage?, data: AnyObject?)
94+
@objc public convenience init(value: Double, icon: NSUIImage?, data: Any?)
9595
{
9696
self.init(value: value)
9797
self.icon = icon

Source/Charts/Data/Implementations/Standard/RadarChartDataEntry.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ open class RadarChartDataEntry: ChartDataEntry
2929
/// - Parameters:
3030
/// - value: The value on the y-axis.
3131
/// - data: Spot for additional data this Entry represents.
32-
@objc public convenience init(value: Double, data: AnyObject?)
32+
@objc public convenience init(value: Double, data: Any?)
3333
{
3434
self.init(value: value)
3535
self.data = data

Tests/Charts/EquatableTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class EquatableTests: XCTestCase {
2323
let data1 = NSObject()
2424
let data2 = NSObject()
2525
let entry1 = ChartDataEntry(x: 5, y: 3, icon: image, data: data1)
26-
let entry2 = ChartDataEntry(x: 5, y: 3, icon: image, data: data2)
26+
let entry2 = ChartDataEntry(x: 5, y: 9, icon: image, data: data2)
2727

2828
XCTAssertFalse(entry1 == entry2)
2929
}

0 commit comments

Comments
 (0)