ios – Swift 2.0 – Google Analytics事件构建器错误 – NSMutableDictionary无法转换为[NSObject:AnyObject]

前端之家收集整理的这篇文章主要介绍了ios – Swift 2.0 – Google Analytics事件构建器错误 – NSMutableDictionary无法转换为[NSObject:AnyObject]前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
完美地使用 Swift 1.2

代码

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

错误

NSMutableDictionary is not convertible to [NSObject : AnyObject]

任何的想法?

解决方法

你错了你的事件.这是正确的方法和一种方法.
let tracker = GAI.sharedInstance().defaultTracker

将事件跟踪器初始化为NSObject

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

在发送方法中将NSObject转换为Anyobject.

tracker.send(eventTracker as! [NSObject : AnyObject])
原文链接:https://www.f2er.com/iOS/330806.html

猜你在找的iOS相关文章