Page - Daily Cost

Screen: AppRoute.dailyCost File: Utiliship/Features/DailyCost/DailyCostView.swift ViewModel: Utiliship/Features/DailyCost/DailyCostViewModel.swift Use Case: Utiliship/Features/DailyCost/DefaultDailyCostCalculationUseCase.swift

Purpose

Calculates the daily depreciation cost of a purchase. The user enters an optional item name, purchase price, and the date they started using it. The use case divides the total cost by the number of days elapsed since the start date, returning breakdowns per day, week, month, and year.

Component Tree

DailyCostView
└── ScrollView
    └── VStack
        ├── itemNameField      — AppTextField bound to state.itemName (optional)
        ├── purchasePriceField — AppTextField bound to state.purchasePrice
        ├── startDatePicker    — DatePicker bound to state.startDate
        ├── calculateButton    — enabled when state.canCalculate
        ├── resultCard         — shown when state.result != nil
        │   ├── dailyCostRow
        │   ├── weeklyCostRow
        │   ├── monthlyCostRow
        │   └── yearlyCostRow
        └── resetButton
        └── .withBannerAd(placement: .dailyCost)

ViewModel State

FieldTypeDescription
itemNameStringOptional label for the item (empty = unnamed)
purchasePriceStringRaw decimal string input
startDateDateDate of purchase; defaults to Date() (today)
resultDailyCostResult?Breakdown returned by DefaultDailyCostCalculationUseCase

Computed properties:

  • isPurchasePriceValidDecimal(string: purchasePrice) != nil && > 0
  • canCalculateisPurchasePriceValid

Data Flow