美文网首页
Swift json转model研究

Swift json转model研究

作者: 光彩影 | 来源:发表于2024-02-28 15:20 被阅读0次

我原先一直使用ObjectMapper(https://github.com/tristanhimmelman/ObjectMapper
因为看库已经几年不维护了(因为苹果后面推出Codable方式)

所以就重新找转化库

由参考文章得到的结论是:
推荐SwiftMacros方案(比如1.0.0版本的CodableWrapper和MetaCodable库)

先集入MetaCodable库
https://github.com/SwiftyLab/MetaCodable
报了:Failed to receive result from plugin (from macro 'Codable') 未知原因,未解决
并且文档也没发现model,class,继承的使用。我需要这功能。 先pass

集入CodableWrapper
https://github.com/winddpan/CodableWrapper
类继承功能支持。使用效果不错,优先推荐

评论区有SmartCodable作者回复:我也去验证看看
还有SmartCodable(已验证功能完好,可使用)
https://github.com/intsig171/SmartCodable
SmartCodable整体使用很不错,验证model,class,继承的使用有问题,先pass。我需要这功能。

然后就是我原先的ObjectMapper,功能稳定性还很ok,还能搭配jsonexport工具使用。

总结:优先使用CodableWrapper,然后ObjectMapper吧

参考:
https://juejin.cn/post/7303741790674731045

相关文章

网友评论

      本文标题:Swift json转model研究

      本文链接:https://www.haomeiwen.com/subject/lpcfzdtx.html