From ea9fea98b34ed1a227e83cb966cc3fa657200159 Mon Sep 17 00:00:00 2001 From: Javier Cicchelli Date: Wed, 12 Apr 2023 16:35:57 +0200 Subject: [PATCH] Implemented the "numberOfSectionsInData" property and the "numberOfDataItems(in: )" and "dataItem(at: )" functions in the LocationsListViewModel view model. --- .../LocationsList/LocationsListViewModel.swift | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Apps/Locations/Sources/Screens/LocationsList/LocationsListViewModel.swift b/Apps/Locations/Sources/Screens/LocationsList/LocationsListViewModel.swift index 7b68701..ebf3e9d 100644 --- a/Apps/Locations/Sources/Screens/LocationsList/LocationsListViewModel.swift +++ b/Apps/Locations/Sources/Screens/LocationsList/LocationsListViewModel.swift @@ -48,6 +48,7 @@ extension LocationsListViewModel: LocationsListViewModeling { // MARK: Properties var viewStatusPublisher: Published.Publisher { $viewStatus } + var numberOfSectionsInData: Int { fetchedResultsController.sections?.count ?? 0 } // MARK: Functions @@ -71,6 +72,21 @@ extension LocationsListViewModel: LocationsListViewModeling { } } + func numberOfDataItems(in section: Int) -> Int { + guard + let sections = fetchedResultsController.sections, + sections.endIndex > section + else { + return 0 + } + + return sections[section].numberOfObjects + } + + func dataItem(at indexPath: IndexPath) -> Location { + fetchedResultsController.object(at: indexPath) + } + } // MARK: - Enumerations