1

So in Swift2.x, below code works without issues:

define:

public class BarChartData
    public convenience init(xVals: [String?]?)
    {
        self.init(xVals: xVals, dataSets: [IChartDataSet]())
    }

    public convenience init(xVals: [NSObject]?)
    {
        self.init(xVals: xVals, dataSets: [IChartDataSet]())
    }

init:

let xs = Array(1..<10).map { return Double($0) }
let data = BarChartData(xVals: xs)

However in Swift3, Xcode8 GM throws me error:

Cannot invoke initializer for type 'BarChartData' with an argument list of type '(xVals: [Double])'

If I change to

let data = BarChartData(xVals: xs.map { i in return i as NSObject })

Then it will work.

It seems in Swift3, the bridge between [Double] and [NSObject] is gone. Is there any documentation about this change or it's a bug?

Wingzero
  • 9,644
  • 10
  • 39
  • 80
  • 1
    See [SE-0072: Fully eliminate implicit bridging conversions from Swift](https://github.com/apple/swift-evolution/blob/master/proposals/0072-eliminate-implicit-bridging-conversions.md). You could also write the conversion as `xs as [NSObject]` – Hamish Sep 08 '16 at 09:55
  • 1
    Also documented in the beta 6 release notes: *"Bridging conversions are no longer implicit. The conversion from a Swift value type to its corresponding object can be forced with `as`."* – Martin R Sep 08 '16 at 09:57
  • 1
    As @Hamish writes above, but to specify w.r.t. your comment _"It seems in Swift3, the bridge between `[Double]` and `[NSObject]` is gone"_: it's only the _implicit_ bridging that has been removed. – dfrib Sep 08 '16 at 09:58
  • @Hamish thanks so much, please answer and I will accept it – Wingzero Sep 08 '16 at 09:58
  • Thanks guys! Solved – Wingzero Sep 08 '16 at 10:00

0 Answers0