gpt4 book ai didi

swift - 如何使用 ObjectMapper 在 Realm List 中映射 JSON 中的整数数组

转载 作者:行者123 更新时间:2023-11-30 11:02:46 27 4
gpt4 key购买 nike

我有 JSON:

{ 
"id": 5,
"name": "Name of object",
"filter_ids": [ 10, 15, 20 ]
}

我使用ObjectMapper用于将 JSON 解析为 Realm 对象。

我在对象中有变量:

dynamic var identifier: Int = 0 
dynamic var name: String = ""
var filter_ids = List<Int>()

如何映射filter_ids var?

func mapping(map: Map)  {
identifier <- map["id"]
name <- map["name"]
filter_ids <- map["filter_ids"] //?????? not work
}

最佳答案

我使用了cocoaPod(迦太基也可以)ObjectMapperAdditions

filter_ids <- (map["filter_ids"], RealmTypeCastTransform())

它适用于 Int、String、Bool 数组。

Duplicated discussion

关于swift - 如何使用 ObjectMapper 在 Realm List 中映射 JSON 中的整数数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53116880/

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