RetailApp is a modern iOS application built using SwiftUI and Swift. It demonstrates best practices in iOS development, including dependency injection, clean architecture, and the coordinator pattern. The app allows users to browse products, view product details, and add items to their cart.
- Product Listing: Browse a list of available products.
- Product Details: View detailed information about a product.
- Add to Cart: Add products to the shopping cart.
- Dependency Injection: Uses Swinject for dependency management.
- Coordinator Pattern: Implements a coordinator pattern for navigation.
- Unit Testing: Includes unit tests for critical components.
- SwiftUI: For building the user interface.
- Swinject: For dependency injection.
- Coordinator Pattern: For managing navigation flow.
- Combine: For reactive programming (if applicable).
- XCTest: For unit testing.
- Xcode 14 or later.
- Swift 5.7 or later.
- macOS Ventura or later (for Xcode compatibility).
- Clone the repository:
git clone /~https://github.com/ANSCoder/RetailApp.git
- Open the project in Xcode:
cd RetailApp open RetailApp.xcodeproj
- Build and run the project using Xcode.
The project is organized into the following directories:
RetailApp/
├── Sources/
│ ├── Models/ # Data models (e.g., Product)
│ ├── Views/ # SwiftUI views
│ ├── ViewModels/ # ViewModels for SwiftUI views
│ ├── Services/ # Service layer (e.g., CartService, AnalyticsService)
│ ├── Coordinators/ # Navigation coordinators
│ ├── DIContainer/ # Dependency injection setup
│ └── Utilities/ # Helper classes and extensions
├── Tests/ # Unit tests
└── RetailApp.xcodeproj # Xcode project file
The app uses Swinject for dependency injection. All dependencies are registered in the DependencyMap
struct and resolved using the DIContainer
.
container.register(CartService.self) { _ in
CartManager()
}
let cartService = DIContainer.shared.resolve(CartService.self)
The app uses a coordinator pattern to manage navigation. Each screen has a corresponding coordinator that handles navigation logic.
final class ProductDetailCoordinator: Coordinator {
private let product: Product
private let resolver: Resolver
init(product: Product, resolver: Resolver) {
self.product = product
self.resolver = resolver
}
func start() -> AnyView {
let viewModel = resolver.resolve(ProductDetailViewModel.self, argument: product)!
return AnyView(ProductDetailView(viewModel: viewModel))
}
}
The app includes unit tests for critical components, such as ViewModels and services. Tests are located in the Tests
directory.
- Open the project in Xcode.
- Select the
RetailAppTests
target. - Press
Cmd + U
to run all tests.
Contributions are welcome! If you'd like to contribute to the project, please follow these steps:
- Fork the repository.
- Create a new branch for your feature or bugfix.
- Commit your changes.
- Submit a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.
- Swinject for dependency injection.
- SwiftUI for building the user interface.
- GitHub for hosting the repository.
For questions or feedback, please contact:
- Anand Nimje
GitHub: ANSCoder