From b779e92ef6cd33f5ad79181f53df7597696914e1 Mon Sep 17 00:00:00 2001 From: mlch911 Date: Sat, 14 Sep 2024 15:29:04 +0800 Subject: [PATCH 1/2] Fix: iOS App on Mac can move TableViewCell by default --- Sources/RxDataSources/TableViewSectionedDataSource.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/RxDataSources/TableViewSectionedDataSource.swift b/Sources/RxDataSources/TableViewSectionedDataSource.swift index 0ba1558..daf48e6 100644 --- a/Sources/RxDataSources/TableViewSectionedDataSource.swift +++ b/Sources/RxDataSources/TableViewSectionedDataSource.swift @@ -37,8 +37,8 @@ open class TableViewSectionedDataSource configureCell: @escaping ConfigureCell, titleForHeaderInSection: @escaping TitleForHeaderInSection = { _, _ in nil }, titleForFooterInSection: @escaping TitleForFooterInSection = { _, _ in nil }, - canEditRowAtIndexPath: @escaping CanEditRowAtIndexPath = { _, _ in true }, - canMoveRowAtIndexPath: @escaping CanMoveRowAtIndexPath = { _, _ in true }, + canEditRowAtIndexPath: @escaping CanEditRowAtIndexPath = { _, _ in false }, + canMoveRowAtIndexPath: @escaping CanMoveRowAtIndexPath = { _, _ in false }, sectionIndexTitles: @escaping SectionIndexTitles = { _ in nil }, sectionForSectionIndexTitle: @escaping SectionForSectionIndexTitle = { _, _, index in index } ) { From 8f9ed19658f845e4c4dd0571b54844f72a244221 Mon Sep 17 00:00:00 2001 From: mlch911 Date: Fri, 14 Nov 2025 14:41:01 +0800 Subject: [PATCH 2/2] safe access --- .../CollectionViewSectionedDataSource.swift | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/Sources/RxDataSources/CollectionViewSectionedDataSource.swift b/Sources/RxDataSources/CollectionViewSectionedDataSource.swift index ebb5645..a6e1753 100644 --- a/Sources/RxDataSources/CollectionViewSectionedDataSource.swift +++ b/Sources/RxDataSources/CollectionViewSectionedDataSource.swift @@ -79,7 +79,23 @@ open class CollectionViewSectionedDataSource self._sectionModels[indexPath.section] = section } } - + + open subscript(safe section: Int) -> Section? { + guard let sectionModel = self._sectionModels[safe: section] else { return nil } + return Section(original: sectionModel.model, items: sectionModel.items) + } + + open subscript(safe indexPath: IndexPath) -> Item? { + get { + _sectionModels[safe: indexPath.section]?.items[safe: indexPath.item] + } + set(item) { + guard var section = self._sectionModels[safe: indexPath.section] else { return } + section.items[safe: indexPath.item] = item + self._sectionModels[indexPath.section] = section + } + } + open func model(at indexPath: IndexPath) throws -> Any { guard indexPath.section < self._sectionModels.count, indexPath.item < self._sectionModels[indexPath.section].items.count else { @@ -167,3 +183,19 @@ open class CollectionViewSectionedDataSource } } #endif + +private extension Array { + subscript(safe index: Int) -> Element? { + get { + (0..