5

I am having the trouble in mapping json to my objects array with ObjectMapper. Here is my model object.

class Participant : Mappable {

var user_global_id: String!
var user_app_id: String!

init(){
}

required init?(_ map: Map) {
}

// Mappable
func mapping(map: Map) {
    user_global_id    <- map["user_global_id"]
    user_app_id    <- map["user_app_id"]
}
}

And my json looks: "[{\"user_global_id\":5093363330056192,\"user_app_id\":11}]"

I am calling ObjectMapper:

let participants = Mapper<[Participant]>().map(json["registeredParticipants"])

Above line gives error: Type '[Participant]' does not conform to protocol 'Mappable'

1 Answer 1

9

The main mistake is in passing the array as generic attribute. Here is the solution

 Mapper<Participant>().mapArray(json["registeredParticipants"])
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.