gpt4 book ai didi

swift 2 : How to downcast an Array of Objects

转载 作者:行者123 更新时间:2023-11-28 12:32:37 24 4
gpt4 key购买 nike

我有这个数组,我正在尝试将其 POST 到后端,但对所有的转换感到很困惑

valuesDictionary=["medication": Optional("Novocain"), "dateOfBirth": Optional(2001-    01-01 00:00:00 +0000), "lastName": Optional("Berthold"), "allergies":     Optional("Heuschnupfen"), "firstName": Optional("Alexander"), "Blutgruppe": Optional("A"), "PostalAddress": Optional(Eureka.PostalAddress(street: Optional("Gleimstraße"), state: nil, postalCode: Optional("10123"), city: Optional("Berlin"), country: Optional("DE")))]

尝试将其输入:

let request = Alamofire.request(.POST, Config.profileUpdate, parameters: valuesDictionary , encoding: .JSON)

我尝试了不同的方法,例如:

let valuesDictionary = form.values() as! [String:AnyObject]

向下转换为预期的形式,但它只是显示:

fatal error: can't unsafeBitCast between types of different sizes

最佳答案

Optionals 不是 AnyObject,因为 Optional 是一个 enum(值类型)。在将可选值放入字典之前,您需要先对其进行解包。

关于 swift 2 : How to downcast an Array of Objects,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41703109/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com