Let's say I have class with Date
property
class SomeModel {
..some properties
let date: Date = Date(timeIntervalSince1970: 1505050)
..more properties
}
and I need to display it using this transformation (or any other, just example)
func createString(from date: Date) -> String {
let formatter = DateFormatter()
formatter.dateFormat = "MM dd yyyy HH:mm:ss"
let stringifyDate = formatter.string(from: model.applicationDate)
let monthSymbols = formatter.shortMonthSymbols
let monthIndex = Calendar.current.component(.month, from: model.applicationDate)
let monthName = monthSymbols![monthIndex-1]
return monthName + String(stringifyDate.dropFirst(2))
}
Using Model-View-Presenter pattern, should I pass SomeModel
to View
and perform transformation there, what would be easier since other properties are String
/Int
and it is easy to display them. Or should I create properties for each SomeModel
field
var someText: String {
return model.someText
}
var stringDate: String {
return createString(from: model.date)
}
..other properties
and then call updateUI
like
func updateUI() {
someLabel.text = presenter.someText
dateLabel.text = presenter.stringDate
..other properties
}
Or even it is ok to combine both, but it sounds like bad idea since View
gets Date
property anyway.