我无法将一个Swift字典转换为NSDictionary
。我使用了Swift的枚举作为我的字典键:
enum StringEnum : String {
case Lemon = "lemon"
case Orange = "orange"
}
var swiftDictionary = [StringEnum: AnyObject]()
swiftDictionary[.Lemon] = "string value"
swiftDictionary[.Orange] = 123
当我尝试使用 as
关键字将它转换为 NSDictionary
时:
let objcDictionary: NSDictionary = swiftDictionary as NSDictionary
我遇到了编译器错误:
'[StringEnum : AnyObject]' is not convertible to 'NSDictionary'
这些类型的字典可以转换吗?还是需要循环Swift字典并手动创建
NSDictionary
?
.rawValue
。 - Islam