SwiftUI iOS app that simulates real-time stock prices for 25 symbols over a shared WebSocket echo connection.
- Exactly 25 required symbols.
- Single shared WebSocket connection for app lifecycle.
- JSON payload shape:
{"symbol":"AAPL","price":226.84,"changePercent":1.23}
- Feed updates every 2 seconds when started.
- Updates apply only from echoed WebSocket messages.
- List sorted by price descending.
- Deep links:
stocks://symbol/NVDA.
Stock(Identifiable)StockMessage(Codable)
WebSocketServicingPriceFeedGeneratingTickerServicing
WebSocketClient(low-level socket)WebSocketManager(protocol-conforming service)PriceFeedEngine(volatility simulation ±0.2%...±2.5%)TimerTickerService(runtime ticker)
AppDependencieswith.live()composition.- Live dependencies create exactly one websocket service instance used by
StocksViewModel.
StocksViewModelowns stocks, feed state, connection state, sorting, flashing, and message application.- Depends only on protocols via constructor injection.
- 100% SwiftUI.
- Views consume
@EnvironmentObject var viewModel: StocksViewModel. - Navigation via
NavigationStack+.navigationDestination(for: Stock.self).
Configured URL scheme: stocks
Examples:
stocks://symbol/AAPLstocks://symbol/NVDA
Unit tests use mocks/fakes to avoid network and real timers:
- manual ticker tick injection,
- inbound message injection,
- deterministic sorting/update assertions.
- Open
RealTimePriceTracker.xcodeprojin Xcode. - Select an iOS simulator (for example iPhone 16).
- Build and run.
- Tap Start to begin updates and Stop to pause feed updates.
