Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data as any #3863

Merged
merged 3 commits into from
Apr 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ open class BarChartDataEntry: ChartDataEntry
}

/// Constructor for normal bars (not stacked).
public convenience init(x: Double, y: Double, data: AnyObject?)
public convenience init(x: Double, y: Double, data: Any?)
{
self.init(x: x, y: y)
self.data = data
Expand All @@ -51,7 +51,7 @@ open class BarChartDataEntry: ChartDataEntry
}

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

/// Constructor for stacked bar entries. One data object for whole stack
@objc public convenience init(x: Double, yValues: [Double], data: AnyObject?)
@objc public convenience init(x: Double, yValues: [Double], data: Any?)
{
self.init(x: x, yValues: yValues)
self.data = data
}

/// Constructor for stacked bar entries. One data object for whole stack
@objc public convenience init(x: Double, yValues: [Double], icon: NSUIImage?, data: AnyObject?)
@objc public convenience init(x: Double, yValues: [Double], icon: NSUIImage?, data: Any?)
{
self.init(x: x, yValues: yValues)
self.icon = icon
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ open class BubbleChartDataEntry: ChartDataEntry
/// - y: The value on the y-axis.
/// - size: The size of the bubble.
/// - data: Spot for additional data this Entry represents.
@objc public convenience init(x: Double, y: Double, size: CGFloat, data: AnyObject?)
@objc public convenience init(x: Double, y: Double, size: CGFloat, data: Any?)
{
self.init(x: x, y: y, size: size)
self.data = data
Expand All @@ -61,7 +61,7 @@ open class BubbleChartDataEntry: ChartDataEntry
/// - size: The size of the bubble.
/// - icon: icon image
/// - data: Spot for additional data this Entry represents.
@objc public convenience init(x: Double, y: Double, size: CGFloat, icon: NSUIImage?, data: AnyObject?)
@objc public convenience init(x: Double, y: Double, size: CGFloat, icon: NSUIImage?, data: Any?)
{
self.init(x: x, y: y, size: size)
self.icon = icon
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ open class CandleChartDataEntry: ChartDataEntry
self.icon = icon
}

@objc public convenience init(x: Double, shadowH: Double, shadowL: Double, open: Double, close: Double, data: AnyObject?)
@objc public convenience init(x: Double, shadowH: Double, shadowL: Double, open: Double, close: Double, data: Any?)
{
self.init(x: x, shadowH: shadowH, shadowL: shadowL, open: open, close: close)
self.data = data
}

@objc public convenience init(x: Double, shadowH: Double, shadowL: Double, open: Double, close: Double, icon: NSUIImage?, data: AnyObject?)
@objc public convenience init(x: Double, shadowH: Double, shadowL: Double, open: Double, close: Double, icon: NSUIImage?, data: Any?)
{
self.init(x: x, shadowH: shadowH, shadowL: shadowL, open: open, close: close)
self.icon = icon
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ open class ChartDataEntry: ChartDataEntryBase, NSCopying
/// - y: the y value (the actual value of the entry)
/// - data: Space for additional data this Entry represents.

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

@objc public convenience init(x: Double, y: Double, icon: NSUIImage?, data: AnyObject?)
@objc public convenience init(x: Double, y: Double, icon: NSUIImage?, data: Any?)
{
self.init(x: x, y: y)
self.icon = icon
Expand Down Expand Up @@ -104,8 +104,7 @@ extension ChartDataEntry/*: Equatable*/ {
return true
}

return ((data == nil && object.data == nil) || (data?.isEqual(object.data) ?? false))
Copy link
Member

Choose a reason for hiding this comment

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

I think we shouldn't drop data in compare?

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't see how it is relevant to how two values are equal or not. If a consumer really needs to know if they are using the same object, the can use ===

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

From the Equatable documentation:

Exposing nonvalue aspects of Equatable types other than class identity is discouraged

&& y == object.y
return y == object.y
&& x == object.x
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ open class ChartDataEntryBase: NSObject
@objc open var y = 0.0

/// optional spot for additional data this Entry represents
@objc open var data: AnyObject?
@objc open var data: Any?

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

@objc public convenience init(y: Double, data: AnyObject?)
@objc public convenience init(y: Double, data: Any?)
{
self.init(y: y)

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

@objc public convenience init(y: Double, icon: NSUIImage?, data: AnyObject?)
@objc public convenience init(y: Double, icon: NSUIImage?, data: Any?)
{
self.init(y: y)

Expand All @@ -91,7 +91,6 @@ extension ChartDataEntryBase/*: Equatable*/ {
return true
}

return ((data == nil && object.data == nil) || (data?.isEqual(object.data) ?? false))
&& y == object.y
return y == object.y
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ open class PieChartDataEntry: ChartDataEntry
/// - value: The value on the y-axis
/// - label: The label for the x-axis
/// - data: Spot for additional data this Entry represents
@objc public convenience init(value: Double, label: String?, data: AnyObject?)
@objc public convenience init(value: Double, label: String?, data: Any?)
{
self.init(value: value, label: label, icon: nil, data: data)
}
Expand All @@ -61,7 +61,7 @@ open class PieChartDataEntry: ChartDataEntry
/// - label: The label for the x-axis
/// - icon: icon image
/// - data: Spot for additional data this Entry represents
@objc public convenience init(value: Double, label: String?, icon: NSUIImage?, data: AnyObject?)
@objc public convenience init(value: Double, label: String?, icon: NSUIImage?, data: Any?)
{
self.init(value: value)
self.label = label
Expand All @@ -72,7 +72,7 @@ open class PieChartDataEntry: ChartDataEntry
/// - Parameters:
/// - value: The value on the y-axis
/// - data: Spot for additional data this Entry represents
@objc public convenience init(value: Double, data: AnyObject?)
@objc public convenience init(value: Double, data: Any?)
{
self.init(value: value)
self.data = data
Expand All @@ -91,7 +91,7 @@ open class PieChartDataEntry: ChartDataEntry
/// - value: The value on the y-axis
/// - icon: icon image
/// - data: Spot for additional data this Entry represents
@objc public convenience init(value: Double, icon: NSUIImage?, data: AnyObject?)
@objc public convenience init(value: Double, icon: NSUIImage?, data: Any?)
{
self.init(value: value)
self.icon = icon
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ open class RadarChartDataEntry: ChartDataEntry
/// - Parameters:
/// - value: The value on the y-axis.
/// - data: Spot for additional data this Entry represents.
@objc public convenience init(value: Double, data: AnyObject?)
@objc public convenience init(value: Double, data: Any?)
{
self.init(value: value)
self.data = data
Expand Down
2 changes: 1 addition & 1 deletion Tests/Charts/EquatableTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class EquatableTests: XCTestCase {
let data1 = NSObject()
let data2 = NSObject()
let entry1 = ChartDataEntry(x: 5, y: 3, icon: image, data: data1)
let entry2 = ChartDataEntry(x: 5, y: 3, icon: image, data: data2)
let entry2 = ChartDataEntry(x: 5, y: 9, icon: image, data: data2)

XCTAssertFalse(entry1 == entry2)
}
Expand Down