tristanhimmelman / ObjectMapper

Simple JSON Object mapping written in Swift
MIT License
9.15k stars 1.03k forks source link

How to map 2 JSONs into 1 object #1038

Closed mayixingkong closed 5 years ago

mayixingkong commented 5 years ago

Your JSON dictionary:

json1 { "name1": "ObjectMapper", "url1": "https://github.com/Hearst-DD/ObjectMapper" }

json2 { "name2": "ObjectMapper", "url2": "https://github.com/Hearst-DD/ObjectMapper" }

Your model:


struct Repo: Mappable {
  var name: String!
  var url: URL!

  init(_ map: Map) {
    name <- map["name"]
    url <- map["url"]
  }
}
arsalanj commented 5 years ago

I faced a problem somewhat like this some time ago, what I did was converted the models to dict and then merge then created model from the merged dict

dictionary1.merge(dictionary2) {(current,_) in current}