Simulator.Screen.Recording.-.iPhone.15.Pro.-.2024-07-20.at.15.32.50.mp4
The SpaceX Launches app is a SwiftUI-based application designed to display SpaceX launches using modern Swift technologies. This app utilizes the MVVM (Model-View-ViewModel) design pattern, SwiftData for data management, and URLSession for networking.
- Xcode: 15.4 or later
- iOS: 17.0 or later
The app adheres to the MVVM architecture, which organizes the code into three distinct layers:
- Model: Manages data and main business logic.
- View: Handles the UI and user interactions.
- ViewModel: Serves as an intermediary between the Model and View, managing presentation logic and data transformation.
Assets.xcassets/: Contains asset catalogs used in the app, including images and other resources.Models/: Contains data models used by the application. This includes representations of SpaceX launches, rockets, and related data.Network/: Includes networking components and protocols for handling API requests and responses.Persistence/: Manages local data storage usingModelContainerand SwiftData.Preview Content/: Contains assets used for SwiftUI previews.Utils/: Utility files and extensions used across the application.ViewModels/: Contains the ViewModel classes that manage data and business logic for the views.Views/: Contains SwiftUI views and UI components used in the app.SpaceXLaunchesApp.swift: The main entry point of the application that sets up the app and initializes theModelContainer.
Launch: Represents a SpaceX launch, including details such as launch date, mission name, rocket ID, and related links.Rocket: Contains details about a SpaceX rocket, including its ID, name, and type.LaunchFailure,LaunchLink: Additional data models related to launches.
These models are structured using SwiftData's ModelContainer.
LaunchListView: Displays a list of launches. It usesLaunchesViewModelto fetch and present data and includes UI components like a launch picker and list.DetailView: Shows detailed information about a selected launch. It usesLaunchDetailViewModelto fetch and display rocket details along with other launch information.
LaunchesViewModel: Handles fetching and filtering of launch data. It interacts withNetworkServiceto retrieve data and manage errors.ModelContextProtocol: Protocol for managing data context, which is implemented bySwiftDataModelContext.SwiftDataModelContext: Concrete implementation ofModelContextProtocolthat interacts with SwiftData for data persistence.
LaunchDetailViewModel: Manages the fetching and displaying of rocket details for a specific launch, ensuring that data is fetched only when needed.ModelContextProtocol: Protocol for managing data context, which is implemented bySwiftDataModelContext.
NetworkService: Defines the protocol for network operations to fetch launches and rocket details.SpaceXNetworkService: Concrete implementation that interacts with the SpaceX API, usingURLSessionfor network requests.URLSessionProtocol: Abstracts network requests and is implemented byURLSession.
- SwiftData: Manages local data storage using
ModelContainer, with a schema to handle data persistence.
LaunchesViewModelandLaunchDetailViewModelinclude error handling mechanisms to manage and display error messages effectively.
SpaceXLaunchesApp: The main entry point of the application. It initializes theModelContainerand sets up the initial view withLaunchListView.
To get started with the SpaceX Launches app:
- Clone the repository:
git clone <repository-url> - Open the project in Xcode 15.
- Ensure you have the necessary dependencies and that you are running iOS 17.0 or later.
Here are some areas for future enhancement:
-
Enhance Error Handling:
- Description: Introduce a centralized error handling system or more detailed error reporting.
-
Add Unit and Integration Tests:
- Description: Write comprehensive unit tests for ViewModels and integration tests for network interactions.
-
Improve UI/UX:
- Description: Add loading indicators, animations, and more user feedback mechanisms. Explore accessibility improvements.
-
Abstract Network Layer Further:
- Description: Enhance the abstraction of the network layer to support additional APIs or services.
-
Implement Localization:
- Description: Add support for multiple languages by localizing error messages and other text elements.