A lightweight SwiftUI + Combine application that simulates a real-time stock price feed using a WebSocket echo server.
The app displays 25 stock symbols, generates random prices every 2 seconds, sends them through a WebSocket connection, receives the echoed values, and updates the UI in real time.
This project focuses on clean architecture, testability, reactive streams, and maintainability, rather than UI complexity.
| Light Mode | Dark Mode |
|---|---|
The goal of this implementation was to:
- Build a clean and testable architecture
- Use SwiftUI and Combine
- Implement real-time updates via WebSocket
- Demonstrate modern iOS engineering practices
- Provide unit tests for the business logic
- Structure the project like a production-ready codebase
The implementation followed several engineering principles.
Responsibilities were split across layers:
- UI
- ViewModels
- Networking
- Domain models
- Infrastructure utilities
This allows every component to be tested independently.
Networking components rely on protocol abstractions rather than concrete implementations.
Example:
WebSocketClientProtocol
WebSocketServiceProtocolBenefits:
- dependency injection
- easier testing
- replaceable implementations
The project follows the Model--View--ViewModel architecture.
View (SwiftUI)
โ
ViewModel
โ
Service Layer
โ
WebSocket Client
The ViewModel owns the application state and exposes Combine publishers to the UI.
- User presses Start
- ViewModel opens a WebSocket connection
- Every 2 seconds prices are generated
- Prices are sent through the WebSocket
- The echo server returns the message
- The ViewModel parses the message
- UI updates automatically through Combine
+----------------------+
| SwiftUI View |
| FeedView / Details |
+----------+-----------+
|
v
+----------------------+\
| PriceFeedViewModel |
| (Combine Streams) |
+----------+-----------+
|
v
+----------------------+
| WebSocketService |
| (Business Logic) |
+----------+-----------+
|
v
+----------------------+
| URLSessionWebSocket |
| Client |
+----------------------+
Technology Purpose
SwiftUI UI layer Combine Reactive data streams URLSessionWebSocketTask WebSocket networking XCTest Unit testing Localization API Internationalization
Stock prices are generated every 2 seconds and propagated through the WebSocket echo server.
The UI updates automatically thanks to Combine publishers.
Users can control the feed.
Stopping the feed:
- cancels the timer
- disconnects the WebSocket
A simple connection indicator shows WebSocket status:
- ๐ข Connected
- ๐ด Disconnected
Selecting a stock opens a details view showing:
- symbol
- company name
- price
- price direction
The project includes localization support.
Resources are located in:
Resources/LocalizationExample:
en.lproj/Localizable.strings
ro.lproj/Localizable.stringsSwiftUI automatically resolves localized strings:
Text("Start")When a raw string is required:
String(localized: "Start", bundle: #bundle)Small extensions were added to keep code clean.
Examples include:
- localization helpers
- SwiftUI text helpers
- utility improvements
These reduce boilerplate and improve readability.
Instead of using print(), a centralized logger is used.
Benefits:
- categorized logs
- easier debugging
- productionโready logging
Example categories:
networking
websocket
viewmodelTyped errors are used in the networking layer.
Example:
WebSocketErrorErrors propagate through Combine publishers, allowing the ViewModel to react appropriately.
Unit tests validate the main logic.
Mocks isolate dependencies so tests do not require a real WebSocket connection.
- start feed connects socket
- stop feed disconnects socket
- message parsing
- stock sorting
- error propagation
- connection state updates
- message propagation
- error forwarding
Ensures exactly 25 symbols are produced as required.
RealTimePriceTracker
โ
โโโ App
โ โโโ RealTimePriceTrackerApp.swift
โ โโโ AppContainer.swift
โ
โโโ Configuration
โ โโโ AppConfig.swift
โ
โโโ Core
โ โโโ Errors
โ โโโ Logging
โ โโโ Localization
โ
โโโ Networking
โ โโโ Protocols
โ โโโ Clients
โ โโโ Services
โ
โโโ Stocks
โ โโโ Models
โ โโโ Generators
โ โโโ ViewModels
โ โโโ Views
โ
โโโ Resources
โ โโโ Localization
โ
โโโ Tests
โโโ ViewModelTests
โโโ ServiceTests
โโโ UtilityTests
------------------------------------------------------------------------The architecture prioritizes:
- testability
- modular design
- clear separation of concerns
Decision Reason
-------------- ---------------------------------------
MVVM Clear separation between UI and logic
Protocols Enables dependency injection
Combine Reactive UI updates
DI Container Clean dependency management
------------------------------------------------------------------------- Open in Xcode
- Select an iOS simulator iOS 26+ version
- Run the app
- Press Start to begin the feed
- Click on any stock item to open the detail screen
Future enhancements could include:
- animated price changes
- UI snapshot testing
- WebSocket reconnection strategy
- performance optimization for large lists
- accessibility improvements
This project demonstrates how to build a clean, reactive iOS application using modern Apple frameworks.
Key highlights:
- SwiftUI UI layer
- Combine reactive streams
- WebSocket networking
- Protocolโdriven architecture
- Unit tested business logic
- Localization support
The result is a small but productionโstyle codebase designed to showcase engineering best practices.