Map your objects from MBurger objects
The home objects will be like this:
class Home: NSObject {
@objc var title: URL?
@objc var homeDescription: String?
@objc var images: [MBImage]?
}Let’s add a mapping dictionary in Home like this, so that the section can map its elements to the Home object properties.
static func mappingDictionary() -> [String: String] {
return [“title”: “title”,
“description”: “homeDescription”,
“images”:“images”]
}Now we have to create the array of homes from the MBSections. To do so, let’s add the following in the success block:
self.homes = sections.map({ section -> Home in
let home = Home()
section.mapElements(to: home, withMapping: Home.mappingDictionary())
return home
}We should do the same thing in the News and Gallery viewcontrollers, using different object models and a different mapping dictionary.
We use the MBImages class, which is a representation of images inside a section for convenience.
Now we need to map our MBSection objects to Home objects:
Last updated