PRWeatherApp is a modern iOS weather application built with SwiftUI. It allows users to manage a list of cities, view current weather details, and access historical weather data. The app is designed for maintainability, testability, and a smooth user experience.
- MVVM Pattern: The app uses Model-View-ViewModel for clear separation of concerns.
- Models: Represent weather data, cities, and persistence entities.
- ViewModels: Handle business logic, state management, and data fetching.
- Views: SwiftUI views for UI presentation and user interaction.
- Networking: Abstracted via protocols (
WeatherServiceProtocol,WeatherAPIClientProtocol) for easy mocking and testing. - Persistence: Uses Core Data via a
PersistenceManagerabstraction. - Error Handling: Centralized with
ErrorUtilsfor extracting error messages. - Testing: Includes unit tests for view models and services, with mocks for dependencies.
PRWeatherApp/
├── Features/
│ ├── MainView/
│ ├── DetailsView/
│ └── HistoricalDataView/
├── Helpers/
├── Network/
├── Persistence/
├── Shared/
├── Utilities/
├── Resources/
├── Configs/
├── Preview Content/
├── PRWeatherAppApp.swift
├── ...
PRWeatherAppTests/
PRWeatherAppUITests/
- Features/: Contains feature modules (Main, Details, Historical Data) with their Views, ViewModels, and Models.
- Helpers/: Utility functions (e.g., date formatting, temperature conversion).
- Network/: Networking layer (API client, service, bridging header).
- Persistence/: Core Data manager and model files.
- Shared/: Reusable UI components (buttons, backgrounds, fonts).
- Utilities/: Error handling, parsing utilities.
- Resources/: Assets, fonts, colors.
- Configs/: App configuration files (Info.plist).
- Preview Content/: SwiftUI preview assets.
- Tests/: Unit and UI tests for app logic and user flows.
+-------------------+
| Views |
| (SwiftUI UI) |
+-------------------+
|
v
+-------------------+
| ViewModels |
| (State, Logic) |
+-------------------+
|
v
+-------------------+-------------
| Services |
| (WeatherService, localManager) |
+-------------------+-------------
|
v
+-------------------+
| API Client |
| (WeatherAPIClient)|
+-------------------+
|
v
+-------------------+
| Network Layer |
+-------------------+
ViewModels <----> PersistenceManager (Core Data)
Error Handling: ErrorUtils (used throughout)
Parsing: Parser (used by Services)
- User interacts with Views (SwiftUI)
- Views bind to ViewModels (MVVM)
- ViewModels fetch data from Services (networking)
- Services use API Clients to get data from the network
- Data is parsed and returned to ViewModels
- ViewModels may store/fetch data via PersistenceManager (Core Data)
- ViewModels update Views with new state
- SwiftUI: Enables declarative UI and state-driven design.
- Dependency Injection: Improves testability and flexibility.
- Async/Await: Modern concurrency for networking and persistence.
- State Management: UI states (loading, error, empty, loaded) are handled explicitly for robust UX.
- Unit Tests: Located in
PRWeatherAppTests/, covering view models and services. - UI Tests: Located in
PRWeatherAppUITests/. - How to Run Tests:
- In Xcode, select
Product > Testor pressCmd+U.
- In Xcode, select
Last updated: October 20, 2025