사용자 정의 ObjectMapper 클래스가 있습니다. 데이터를 기반으로 요소를 다른 객체 유형에 매핑하려고합니다. 다음과 같은 논리를 구현했습니다. 하지만 그것은 나에게 값만주고, 단지 null 만 제공합니다.ObjectMapper 전체 요소 조건부 매핑
class FeedObject : Object, Mappable {
dynamic var post : HomeDataModel?
dynamic var friends : Friends?
required convenience init?(map: Map) {
self.init()
}
func mapping(map: Map) {
var Mtype = ""
Mtype <- map["type"]
print("TYPEEEEEE", Mtype)
if Mtype == "FRIENDS" {
friends <- map
}
else {
post <- map
}
}
}
어떻게 이런 종류의 매핑을 구현할 수 있습니까?
샘플 JSON -
{ "feed_objects": [ { "type": "NORMAL", "status": "none", "invited": false, "comment": "hello", "time": "00:12" }, { "type": "NORMAL", "status": "none", "invited": true, "comment": "How are you?", "time": "04:15" }, { "type": "FRIENDS", "display_text": "Your friends are here.", "count": 23 }, { "type": "NORMAL", "status": "verified", "invited": true, "comment": "great", "time": "09:32" }] }
JSON 응답을 공유 할 수 있습니까? –
@anilkukdeja 샘플을 추가했습니다. –
제 대답을 확인하십시오. –