This project is a simple example of using SwiftUI with MVVM architecture to list and add products by calling an API.
- Fetch and display a list of products from an API
- Add a new product via an API call
- Uses Combine framework for handling asynchronous events
- iOS 14.0+
- Xcode 12.0+
- Swift 5.3+
-
Clone the repository:
-
Open the project in Xcode:
- open SwiftUIListView.xcodeproj
-
Build and run the project on your preferred simulator or device.
- Launch the app.
- You will see a list of products fetched from the API.
- Tap the "+" button to add a new item.
- Enter the product details and add product.
- The new product will be added to the list.
The project follows the MVVM architecture pattern:
- Model: Represents the data and business logic. This includes API data models.
- View: SwiftUI views that display the data.
- ViewModel: Manages the data for a view by interacting with the model and preparing the data for presentation in the view.
SwiftUIListView/
βββ SwiftUIListViewApp.swift # Entry point of the app
βββ Models/
β βββ Product.swift # Data model for items fetched from the API
β βββ AddProductSuccess.swift # Data model for add item response
βββ Views/
β βββ Splash/
β β βββ SplashScreen.swift # Splash with center app logo
β βββ ProductList/
β β βββ ProductList.swift # Main view displaying the list all products
β β βββ ProductCell.swift # Single product row screen
β βββ AddProduct/
β β βββ AddProductScreen.swift # Add product screen design
β β βββ SelectProductType.swift # Select product type screen design
β βββ CommanView/
β β βββ CustomButton.swift # Create customzied button for app
β β βββ CustomTextFiled.swift # Create customzied textfiled for app
β β βββ ErrorView.swift # Create customzied textfiled validation error view
βββ ViewModels/
β βββ ProductListViewModel.swift # ViewModel for managing products data
β βββ AddProductViewModel.swift # ViewModel for managing add product data
β βββ SelectProductTypeViewModel.swift # ViewModel for managing product type data
βββ Services/
β βββ APIService.swift # Service for making APIs calls
β βββ APIEndpoint.swift # Handle base url and apis end points
βββ Extension/ # Enhance existing types with new functionality
βββ Data.swift
βββ Date.swift
βββ Float.swift
βββ View.swift
- SwiftUI Documentation
- MVVM Architecture Patterns
- For any questions or suggestions, please open an issue or contact akabaridixit009@gmail.com