yeah, it's a solution, but not perfect for following case.
JSON from server
{
id: "4",
key: "web_banner",
data: [
{
id: "11",
title: "app",
description: "",
}
]
}
i use ObjectMapper for mapping, so as the JSON schema, i create the following models
class Advertising: Object, Mappable {
dynamic var id = ""
dynamic var key = ""
private var data = [AdvertisingData]()
{
willSet{// **i have to do this for Store it, it will be empty in realm if not do this**
dataList.removeAll()
dataList.appendContentsOf(newValue)
}
}
let dataList = List<AdvertisingData>()
convenience required init?(_ map: Map) {
self.init()
}
func mapping(map: Map) {
id <- map["id"]
key <- map["advertising_key"]
data <- map["advertising_data"]
}
override class func ignoredProperties() -> [String] {
return ["data"]
}
}
class AdvertisingData: Object, Mappable {
dynamic var id = ""
dynamic var title = ""
dynamic var theDescription = “”
convenience required init?(_ map: Map) {
self.init()
}
func mapping(map: Map) {
id <- map["id"]
title <- map["title"]
theDescription <- map["description"]
}
}
- i must declare the data in class Advertising just for sync data to dataList,
- i have to ignore the property data this is my solution, too ugly, some good idea? Thank you in advance