我从swift2.3移植到swift3并遇到了以下问题。
我正在尝试在下面的函数中返回值字典字典。但是收到错误var str = "my text";
foreach (ListViewItem item in listView1.Items)
{
if (item.Content.Equals(str))
{
//... do your stuff
}
}
在尝试寻找答案之后,我尝试手动将值桥接为Contextual type 'AnyObject' Cannot be used with dictionary literal
,但无济于事。
AnyObject
typealias Payload = [String: AnyObject]
答案 0 :(得分:1)
使用Any
代替AnyObject
:
func toCreatePayload() -> Payload {
let payload: [String: [String:Any]] =
["saving_rule": ["description": title,
"amount": amount!,
"background_color": (backgroundColor?.toHexString())!,
"saving_rule_category_id": category!.remoteId,
"saving_rule_sub_category_id": subCategory != nil ? subCategory!.remoteId : "",
"saving_rule_condition_id": condition != nil ? condition!.remoteId : "",
"saving_rule_condition_customizations_attributes": customizations.map({$0.toCreatePayload()}),
"suspended": "false"]
]
return payload
}
区别: