Page - Unit Converter

Screen: AppRoute.unitConverter File: Utiliship/Features/UnitConverter/UnitConverterView.swift ViewModel: Utiliship/Features/UnitConverter/UnitConverterViewModel.swift

Purpose

Converts a value between any two units within a selected category (length, weight, temperature, area, volume, speed, data, …). Shows the primary result pair plus an expandable "all conversions" table. The ViewModel persists the last-used category and units across sessions and respects the user's metric/imperial system preference.

Component Tree

UnitConverterView
└── VStack
    ├── categoryPicker          — Picker bound to state.selectedCategory
    ├── inputSection
    │   ├── AppTextField        — state.inputValue
    │   └── fromUnitPicker      — state.fromUnit (filtered to category)
    ├── resultSection
    │   ├── primaryResult       — state.result.convertedValue + state.toUnit
    │   └── toUnitPicker        — state.toUnit
    ├── allConversionsToggle    — toggles state.showAllResults
    └── allConversionsTable     — ForEach state.allConversions (when showAllResults)
    └── .withBannerAd(placement: .unitConverter)

ViewModel State

FieldTypeDescription
selectedCategoryUnitCategoryActive conversion domain (length, weight, …)
inputValueStringRaw decimal string input
fromUnitUnitTypeSource unit (default .meter for length)
toUnitUnitTypeTarget unit (default .kilometer)
resultUnitConversionResult?Primary conversion result + allConversions map
errorString?Parse or conversion error
showAllResultsBoolExpands the all-conversions table (default false)
lastMeasurementSystemUserSettings.MeasurementSystem?Cached preference for smart unit defaults

Data Flow