4

Before Swift 3, my code for creating an AWSTask with a result was something like this:

let results = ["resultOne", "resultTwo"]
let task = AWSTask(result: results)

But using Swift 3, I'm getting this error message from Xcode 8:

Cannot convert value of type '[String]' to expected argument type '_?'

Has anyone else come across this? Thanks so much!

Mark Mckelvie
  • 343
  • 4
  • 13

1 Answers1

5

Simply add as NSArray like this:

let results = ["resultOne", "resultTwo"] as NSArray
let task = AWSTask(result: results)

Because results must confirm to Protocol AnyObject when define AWSTask:

open class AWSTask<ResultType : AnyObject> : NSObject {...}

In swift 2.2 ["resultOne", "resultTwo"] is auto brige to NSArray,

But in swift 3.0 you have to brige [String] to NSArray manually.

This is the explanation:

https://github.com/apple/swift-evolution/blob/master/proposals/0072-eliminate-implicit-bridging-conversions.md

beeth0ven
  • 1,857
  • 15
  • 18
  • Thanks so much! Before reading your answer I noticed the cast to NSArray got rid of the error, but your answer taught me why. – Mark Mckelvie Sep 18 '16 at 10:06