Varis Darasirikul Varis Darasirikul - 10 months ago 72
iOS Question

Cannot convert value of type 'NSMutableDictionary' to type '[NSObject: AnyObject]' in coercion for google ios Analytics

I want to add google Analytics ios into my project but i got some problems when i tried to paste their code into my app like the code below.

var tracker = GAI.sharedInstance().defaultTracker
tracker.set(kGAIScreenName, value: "rootPlayView")

var builder = GAIDictionaryBuilder.createScreenView()
tracker.send( as [NSObject : AnyObject])

Then i got an error like this

enter image description here

how can i fix this?



try this

var builder = GAIDictionaryBuilder.createScreenView().build() as! [NSObject : AnyObject]


for screen track

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

for event Track

  let tracker = GAI.sharedInstance().defaultTracker
let builder: NSObject = GAIDictionaryBuilder.createEventWithCategory(
            action: "buttonclicked",
            label: "you pressed xxx button",
            value: nil).build()
tracker.send(builder as! [NSObject : AnyObject])