有人可以帮我解决这个问题吗?我收到这个快速编译器错误:
'Cannot convert value of type 'String' to expected dictionary key type 'NSObject'
let orderParameters =
["customer": [ <- //Getting the error in this line
"first_name": "Jon",
"last_name":"Doe",
"email": "john.doe@gmail.com"],
"shipping": "free-shipping",
"gateway": "dummy",
"bill_to": [
"first_name": "Jon",
"last_name": "Doe",
"address_1": "123 Sunny Street",
"address_2": "Sunnycreek",
"city": "Sunnyvale",
"county": "California",
"country": "US",
"postcode": "CA94040",
"phone": "18768509132"],
"ship_to": "bill_to"
] as [NSObject: AnyObject]
我是否为“客户”参数插入as NSObject?
最佳答案
不要将写为[NSObject: AnyObject]
,而将写为[AnyHashable: Any]
。
这是 Swift 3 表达字典一般概念的方式。
关于swift - 将字符串转换为 NSObject Swift 3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40597796/