As of April 12th, you must go to Progress SupportLink to create new support cases or to access existing cases. Please, bookmark the SupportLink URL and use the new portal to contact the support team.
Trouble with Property Mapping: Getting Array of Custom Objects.
S
Shae Hazelwood
started a topic
almost 6 years ago
I have an array of objects I'm trying to get out of one of my collections. I've followed along using their docs and also some Googling and I believe I'm close to the solution, however not close enough. Here's what I have:
class Clothing: Entity {
var categories: [Category]!
var gender: String!
override class func collectionName() -> String {
//return the name of the backend collection corresponding to this entity
return "categories"
}
override func propertyMapping(_ map: Map) {
super.propertyMapping(map)
categories <- map["clothing"]
gender <- map["gender"]
}
}
class Category: NSObject, Mappable{
var title: String?
var image: String?
convenience required init?(map: Map) {
self.init()
}
func mapping(map: Map) {
title <- map["category"]
image <- map["image"]
}
}
I'm able to get the right gender, but the array of categories doesn't seem to get mapped to the Category object. Any thoughts?
You should use "List<Category>()" instead "[Category]!". As per Kinvey documentation, List<T> types must be unmutable using the keyword let instead of the usual declaration dynamic var.
Also, each property in your entity should be mapped using the following scheme: <member variable> <- ("<backend property>", map["<backend property>"])
Shae Hazelwood
I have an array of objects I'm trying to get out of one of my collections. I've followed along using their docs and also some Googling and I believe I'm close to the solution, however not close enough. Here's what I have:
I'm able to get the right gender, but the array of categories doesn't seem to get mapped to the Category object. Any thoughts?