ExCodable icon indicating copy to clipboard operation
ExCodable copied to clipboard

能支持[String: Any]和[Any]吗

Open yxh265 opened this issue 2 years ago • 4 comments

https://github.com/levantAJ/AnyCodable https://stackoverflow.com/questions/44603248/how-to-decode-a-property-with-type-of-json-dictionary-in-swift-45-decodable-pr

yxh265 avatar Nov 21 '22 04:11 yxh265

可以考虑,等有空看一下。目前可以用 这个 变通实现。

iwill avatar Nov 22 '22 04:11 iwill

我试着改了一下。 已经提交了一个合并申请。 大佬看看。

https://github.com/yxh265/ExCodable/tree/develop

支持模型定义如下:

struct testModel: ExAutoCodable {
@ExCodable
var jumpParam: [String: Any]? = [:]

@ExCodable
var matchs: [Any] = []
}

yxh265 avatar Nov 22 '22 05:11 yxh265

动手能力好强 👍🏿

但是把另一个框架的代码直接内置进来,并不是一个理想的选择,在同时使用这两个框架的 app 中会产生冲突。

建议通过组合的方式来达到同样的效果:ExCodable 提供了 ExCodableDecodingTypeConverter 协议,用来做自定义的类型转换。是否可以复用该协议,如有必要,对这个协议做适当的改造也是 OK 的。

iwill avatar Nov 22 '22 06:11 iwill

因为另一个框架的代码它没做到pod,所以临时直接放进来了。 嗯,(ExCodable 提供了 ExCodableDecodingTypeConverter 协议)是个好方法,也期待你的更新。

yxh265 avatar Nov 22 '22 07:11 yxh265