Reputation: 899
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'
Upvotes: 5
Views: 3534
Reputation: 899
The main mistake is in passing the array as generic attribute. Here is the solution
Mapper<Participant>().mapArray(json["registeredParticipants"])
Upvotes: 9