Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift 2.0 - Google Analytics Event builder error - NSMutableDictionary is not convertible to [NSObject : AnyObject]

Worked perfectly on Swift 1.2

code :

 var build = GAIDictionaryBuilder.createEventWithCategory("Record Counter", action: "Images Taken", label: "usersad", value: 1  ).build() as [NSObject : AnyObject]
 self.tracker.send(build)

Error :

NSMutableDictionary is not convertible to [NSObject : AnyObject]   

Any idea?

like image 285
Roi Mulia Avatar asked Sep 15 '15 02:09

Roi Mulia


1 Answers

You're casting your event wrong. Here is the correct way and one way of doing it.

let tracker = GAI.sharedInstance().defaultTracker

Initialize your Event Tracker as NSObject

let eventTracker: NSObject = GAIDictionaryBuilder.createEventWithCategory(
                "ui_action",
                action: "button_press",
                label: "play",
                value: nil).build()

Cast your NSObject as Anyobject within the send method.

tracker.send(eventTracker as! [NSObject : AnyObject])
like image 85
Brian Nezhad Avatar answered Nov 05 '22 11:11

Brian Nezhad