NSNotificationCenter userInfo 中的字典值类型

Dictionary value type in NSNotificationCenter userInfo

执行下一段代码时:

func locationManager(manager: CLLocationManager!, didChangeAuthorizationStatus status: CLAuthorizationStatus) {

    NSNotificationCenter.defaultCenter().postNotificationName("gotAuthorization", object: nil, userInfo: ["status": status])

}

我遇到下一个错误:

cannot invoke 'postNotificationName' with argument list of type...

另一方面,如果我将状态更改为一些简单的值,如字符串或整数,则一切正常。

CLAuthorizationStatus 是一个枚举,最终是 Int32。那么将它作为字典的值有什么问题呢?

我在这里错过了什么:\

参数接受[NSObject:AnyObject]的字典?并不意味着听起来像编译器,但 Int32 不符合 AnyObject 协议。它不会自动桥接到 NSNumber,因此您需要对其进行转换。

["status": Int(status.rawValue)]