tristanhimmelman / ObjectMapper

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

Mapping Object to another Object #1033

Closed avjiang closed 5 years ago

avjiang commented 5 years ago

Hi! Great Library!

I would like to ask, can we use this Library to map properties of an object to another object that is also conforming to Mappable Protocol?

For example

     let sampleObject = SampleObject()
     sampleObject.property = "Property"

     /// Map sampleObject property value to another object with same property name
     let testObject = TestObject()
     /// testObject.property = "Property". Mapped from sampleObject

Thanks!

muhrifqii commented 5 years ago

This one comes up in my mind, haven't tested it. Let's say you have exactly same mapping key for property

import ObjectMapper

let testObject = TestObject(JSON: sampleObject.toJSON())
tristanhimmelman commented 5 years ago

Please see the following function in the Mapper class https://github.com/tristanhimmelman/ObjectMapper/blob/master/Sources/Mapper.swift#L59