Sunday, November 19, 2023
HomeiOS Developmentios - Is there a bonus to hiding the mannequin layer?

ios – Is there a bonus to hiding the mannequin layer?


I used to be taking a look at a tutorial on the MVVM structure sample.

It says that views ought to by no means have direct entry to the mannequin. So all views are all the time hidden behind a view mannequin.

For instance:

Mannequin

struct Location: Codable, Equatable {

//MARK: Properties

let id: String
let identify: String
let nation: String

//
let latitude: Double
let longitude: Double

init(id: String, identify: String, nation: String, latitude: Double, longitude: Double) {
    self.id = id
    self.identify = identify
    self.nation = nation
    self.latitude = latitude
    self.longitude = longitude
}
}

View Mannequin that disguise the mannequin layer

closing class LocationCellViewModel: Identifiable {

//MARK: Properties

non-public let location: Location

//
var locationViewModel: LocationViewModel {
    .init(location: location)
}

// MARK: - Initialization

init(location: Location) {
    self.location = location
}

// MARK: - Public API

var locationName: String {
    location.identify
}

var locationCountry: String {
    location.nation
}

....

}

View Mannequin that shall be within the view as property

closing class LocationsViewModel {

//MARK: Properties

non-public(set) var locationCellViewModels: [LocationCellViewModel] = []

   ....

 }

Why would possibly it’s higher to have a LocationCellViewModel array as an alternative of a Location array within the LocationsViewModel class? Is there any benefit to doing so?



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments