Nata Mio Nata Mio - 6 months ago 285
iOS Question

Cannot convert value of type NSMutableDictionary? to expected argument type [NSObject: AnyObject]!

i wanted to jump over to use Xcode 8 beta and convert my code, but I'm facing some kind of problem here, i am using Google Analytics SDK to send events,and this is how i used to use it in Swift 2.2 :

let tracker = GAI.sharedInstance().defaultTracker
tracker?.set(kGAIScreenName, value: "ViewController")
let builder = GAIDictionaryBuilder.createScreenView()
tracker?.send(builder?.build() as [NSObject:AnyObject])

But now i want to use Swift 3, its telling me :

Cannot convert value of type NSMutableDicationary to type [NSObject :
AnyObject] in coercion.


You need to make a variable to hold your NSMutableDictionary then pass it to send() method.

let dictionary = (builder?.build())! as NSMutableDictionary
tracker?.send(dictionary as [NSObject: AnyObject]!)