Manju Basha Manju Basha - 1 year ago 37
iOS Question

'NSMutableSet' is not implicitly convertible to 'Set<NSObject>'

I am using coreplot to plot graph in my app.
When i try to assign X-Axis label or major tick location it is throwing error though

NSMutableSet
is converted to Set of NSObject Type.
Here is how i have written my code:

xAxis.axisLabels = xAxisLabels as Set<NSObject>
xAxis.majorTickLocations = xMajorTickLocations as Set<NSObject>


The error thrown is as follows

'NSMutableSet' is not implicitly convertible to 'Set<NSObject>'; did you mean to use 'as' to explicitly convert

Answer Source

You should use native Swift types rather than Foundation collections when possible. This eliminates the need for casting.

var xAxisLabels = Set<CPTAxisLabel>()
var xMajorTickLocations = Set<NSNumber>()