-
-
Notifications
You must be signed in to change notification settings - Fork 6k
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
PieChartData initialisers ambiguous when xVals parameter is nil #224
Comments
Hmmm... This is an interesting problem! In one hand, we have a variable of kind But theoretically it could be solved if we would be able to hint the compiler that "it doesn't matter which constructor you choose" or "THAT one is the right constructor when there's ambiguity". I'm going to try Apple forums for this, who know maybe there is a way... |
It just hit me no the head. We need to just add a constructor that accepts no arguments. So I could have added a constructor which takes only I think it is preferred to have it left as it is, to make things clear. On occasions like this it will not be the prettiest it can be, but it's not that bad! |
My use case was a piechart without any labels (because I want to show them in a different way to the built in way). One option is to be explicit in the parameter naming e.g public init(xStringVals: [String?]?, dataSets: [ChartDataSet]?)
public init(xNSObjectVals: [NSObject]?, dataSets: [ChartDataSet]?) But this messes up the nice uniform API. Another option is to let the compiler decide. public init(_ xVals: [String?]?, dataSets: [ChartDataSet]?)
public init(_ xVals: [NSObject]?, dataSets: [ChartDataSet]?) But now you lose the explicit Or, define constants to use when there is no 1st parameter. let kNilNSObjects = Optional<[NSObject]>.None
let kNilStrings = Optional<[String?]>.None But the user of the API needs know about the cause of the ambiguity when the compiler gives the error and they need to know about this typealias. Lastly, you could maybe just explain this situation in the docs. Designing an API is hard! Thanks for all the work you have put in on this great library. |
You are missing something: |
Not sure if this is a bug but it makes for messy API calls like:
PieChartData(xVals: nil as [String?]?, dataSet: dataSet)
The following API pairs are ambiguous when xVals is set to nil because both are valid so the compiler doesn't know which to choose.
The text was updated successfully, but these errors were encountered: