This project is a demonstration of using SwiftUI with the MVVM (Model-View-ViewModel) architecture pattern to fetch data from an API, store it in CoreData, and display it in a ListView.
- Fetch data from an API.
- Store data in CoreData.
- Display data in a SwiftUI ListView.
- Implement MVVM architecture for better code separation and testability.
- iOS 14.0+
- Xcode 12.0+
- Swift 5.3+
-
Clone the repository:
-
Open the project in Xcode:
- open ListView.xcodeproj
-
Build and run the project on your preferred simulator or device.
The project follows the MVVM architecture pattern:
-
Model: Represents the data and business logic. This includes CoreData entities and 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.
ListView/
βββ ListViewApp.swift # Entry point of the app
βββ Models/
β βββ DocsResponse.swift # Data model for items fetched from the API
β βββ LocalListModel.swift # Data model for items fetched from the Coredata
βββ Views/
β βββ ListView.swift # Main view displaying the list
β βββ ListRow.swift # Subview for displaying individual items
βββ ViewModels/
β βββ ListViewModel.swift # ViewModel for managing item data
βββ Services/
β βββ APIService.swift # Service for making API calls
βββ Persistence/
βββ CoreDataManager.swift # CoreData stack and helper methods
βββ ListView.xcdatamodeld/ # CoreData model
- SwiftUI Documentation
- CoreData Documentation
- MVVM Architecture Patterns
- For any questions or suggestions, please open an issue or contact [email protected]