I am relatively new to SwiftUI and am trying to develop a small app based on what I learned from the iExpense (100days SwiftUI - project 7) project, which stores and lists the expenses for my eCar.
I would like to hear the opinion of the experts how I can pack the following data into one or two data models in order to display them.
I have once the loading costs, with the following properties - I have packaged this as a test in structure form to make it clear:
struct LoadingCostItem: Identifiable, Codable, Comparable {
static func < (lhs: LoadingCostItem, rhs: LoadingCostItem) -> Bool{
lhs.date > rhs.date // sorting by date read
// lhs -> leftHandSite rhs -> rightHandSite
}
var id = UUID()
var date: Date
var kwhCharged: Double
var mileage: Int
var rangeKm: Int
var priceKwh: Double
var priceTotal: Double
}
Then I have the other costs, such as:
struct MiscCostItem: Identifiable, Codable, Comparable {
static func < (lhs: MiscCostItem, rhs: MiscCostItem) -> Bool{
lhs.date > rhs.date // sorting by date read
// lhs -> leftHandSite rhs -> rightHandSite
}
var id = UUID()
var date: Date
var category: String
var description: String
var priceTotal: Double
}
My idea is to create two structures/classes, one for charging costs and then for miscellaneous costs.
Furthermore I would have two views that show the data in a list and a button that creates/pop-up a sheet to enter the data for the loading costs and miscellaneous costs.
I am thinking back and forth if this is the right solution, or if there is not a clever way that I have only one data model and one view, and then work e.g. via filters in the list. However, the difference in the two above structures seems to me very large, so I do not know how I could/should filter this.
I would be glad about your opinion.
Regards,
Ralf