Skip to content

zulus128/AvgSpeed

Repository files navigation

AvgSpeed

AvgSpeed is a watchOS SwiftUI application for tracking live movement speed, average speed, distance, and session history on Apple Watch. This archive is prepared as an engineering sample: runtime integrations stay in the app target, while calculation, filtering, haptic, and max-speed decisions are extracted into pure Swift files covered by unit tests.

What to Review

  • AvgSpeed Watch App/SpeedTracker.swift: Tracking entry points, published runtime state, and startup/stop coordination.
  • AvgSpeed Watch App/SpeedTracker+Lifecycle.swift: Runtime lifecycle helpers, diagnostics, persistence, and timer coordination.
  • AvgSpeed Watch App/SpeedTracker+LocationMetrics.swift: CoreLocation sample filtering, distance accumulation, GPS freshness, and max-speed updates.
  • AvgSpeed Watch App/SpeedTracker+LocationDelegate.swift: CoreLocation delegate bridge into the main-actor tracker.
  • AvgSpeed Watch App/SpeedMetrics.swift: Pure speed, distance, elapsed-time, and unit conversion calculations.
  • AvgSpeed Watch App/SpeedDistanceRules.swift: Distance sample acceptance, estimation, and overlong-gap decisions.
  • AvgSpeed Watch App/MaxSpeedAccumulator.swift: Max-speed spike rejection and confirmation window logic.
  • AvgSpeed Watch App/SpeedHapticRules.swift: Pure watch haptic transition decisions.
  • AvgSpeed Watch App/SpeedTrackerRuntimeRules.swift: Runtime warmup and workout-start recovery decisions.
  • AvgSpeed Watch App/SpeedLocationSmoothingRules.swift: Pure location smoothing rules used by the tracker and tests.
  • AvgSpeed Watch App/SpeedGauge.swift: Reusable SwiftUI gauge rendering.
  • AvgSpeedCoreTests/SpeedMetricsTests.swift: Unit coverage for the calculation and tracker-adjacent rules.

Architecture

  • SpeedTracker owns platform orchestration and published runtime state, but policy decisions are delegated to pure Swift helpers.
  • WorkoutManaging, ComplicationManaging, DiagnosticLogging, and SessionHistoryRecording keep platform services injectable for future integration tests.
  • SwiftUI views are split into focused files for the main screen, gauge, summaries, diagnostics, overlays, Pro settings, and history.
  • StoreKit, theme, and session-history responsibilities are separated into dedicated files instead of one feature bundle.
  • AvgSpeed.storekit defines the local non-consumable Pro product used for StoreKit sandbox testing.

Tests

Run the pure logic unit tests without a simulator or code signing:

swift test

The tests cover average speed calculation, elapsed/moving/stopped time, metric/imperial conversion, GPS freshness, timestamp filtering, startup speed seeding, displayed speed selection, distance-stall alerts, distance sample decisions, max-speed confirmation, haptic transitions, warmup filtering, location smoothing, session-history persistence boundaries, and visible workout-start fallback decisions.

Build

For local validation without signing:

xcodebuild -project AvgSpeed.xcodeproj \
  -scheme "AvgSpeed Watch App" \
  -configuration Debug \
  -destination "generic/platform=watchOS" \
  CODE_SIGNING_ALLOWED=NO build

Signing Placeholders

The review archive replaces App Store, team, bundle, and app-group identifiers with placeholders such as TEAMID1234, com.example.AvgSpeed, and group.com.example.AvgSpeed. To run on a real device, set a valid development team, bundle identifiers, and app group, then enable signing.

Known Limitations

  • The included tests cover pure logic and tracker-adjacent rules. They intentionally avoid simulator-dependent CoreLocation, HealthKit, and WidgetKit integration tests.
  • StoreKit local purchase flows are configured through AvgSpeed.storekit and the shared Xcode scheme; automated StoreKit UI tests are outside this sample archive.
  • SpeedTracker is split across focused runtime extension files because it remains the watch app orchestration boundary; the pure decision logic is factored out so the high-risk calculations remain testable.
  • Session history is stored in app-group UserDefaults, which is appropriate for the small watchOS history payload included here. A larger product would move this to a versioned store.

Tech Stack

  • Swift, SwiftUI
  • watchOS
  • CoreLocation
  • HealthKit / WorkoutKit integration
  • WidgetKit complications
  • StoreKit
  • Swift Package Manager tests

Releases

Packages

Contributors

Languages