Skip to content

DixPatel009/SwiftUI-MVVM-ListView

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

8 Commits
Β 
Β 
Β 
Β 

Repository files navigation

SwiftUI-MVVM-ListView

This project is a simple example of using SwiftUI with MVVM architecture to list and add products by calling an API.

Features

  • 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

Requirements

  • iOS 14.0+
  • Xcode 12.0+
  • Swift 5.3+

Installation

  1. Clone the repository:

  2. Open the project in Xcode:

    • open SwiftUIListView.xcodeproj
  3. Build and run the project on your preferred simulator or device.

Usage

  1. Launch the app.
  2. You will see a list of products fetched from the API.
  3. Tap the "+" button to add a new item.
  4. Enter the product details and add product.
  5. The new product will be added to the list.

Architecture

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.

Project Structure

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                                

Acknowledgements

  • SwiftUI Documentation
  • MVVM Architecture Patterns

Contact

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages