diff --git a/Examples/SampleApp/SampleApp.xcodeproj/project.pbxproj b/Examples/SampleApp/SampleApp.xcodeproj/project.pbxproj index 9a3036e..711a644 100644 --- a/Examples/SampleApp/SampleApp.xcodeproj/project.pbxproj +++ b/Examples/SampleApp/SampleApp.xcodeproj/project.pbxproj @@ -435,7 +435,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 9.3; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -482,7 +482,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 9.3; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; @@ -499,6 +499,7 @@ CLANG_ENABLE_MODULES = YES; DEVELOPMENT_TEAM = 7M6E9TXYGF; INFOPLIST_FILE = "$(SRCROOT)/SampleApp/Info.plist"; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.odigeo.tableviewkit.example; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -516,6 +517,7 @@ CLANG_ENABLE_MODULES = YES; DEVELOPMENT_TEAM = 7M6E9TXYGF; INFOPLIST_FILE = "$(SRCROOT)/SampleApp/Info.plist"; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.odigeo.tableviewkit.example; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -528,6 +530,7 @@ buildSettings = { BUNDLE_LOADER = "$(TEST_HOST)"; INFOPLIST_FILE = SampleAppTests/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.odigeo.SampleAppTests; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -540,6 +543,7 @@ buildSettings = { BUNDLE_LOADER = "$(TEST_HOST)"; INFOPLIST_FILE = SampleAppTests/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.odigeo.SampleAppTests; PRODUCT_NAME = "$(TARGET_NAME)"; diff --git a/TableViewKit/TableViewKitDelegate.swift b/TableViewKit/TableViewKitDelegate.swift index 2197273..f8d6c72 100644 --- a/TableViewKit/TableViewKitDelegate.swift +++ b/TableViewKit/TableViewKitDelegate.swift @@ -77,14 +77,16 @@ open class TableViewKitDelegate: NSObject, UITableViewDelegate { /// Implementation of UITableViewDelegate // swiftlint:disable:next line_length public func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? { - guard let item = manager.item(at: indexPath) as? Editable else { return nil } + guard manager.itemExists(at: indexPath), + let item = manager.item(at: indexPath) as? Editable else { return nil } return item.trailingConfiguration } /// Implementation of UITableViewDelegate // swiftlint:disable:next line_length public func tableView(_ tableView: UITableView, leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? { - guard let item = manager.item(at: indexPath) as? Editable else { return nil } + guard manager.itemExists(at: indexPath), + let item = manager.item(at: indexPath) as? Editable else { return nil } return item.leadingConfiguration } diff --git a/TableViewKit/TableViewManager.swift b/TableViewKit/TableViewManager.swift index 67c45a4..93b60d8 100644 --- a/TableViewKit/TableViewManager.swift +++ b/TableViewKit/TableViewManager.swift @@ -129,4 +129,19 @@ extension TableViewManager { func item(at indexPath: IndexPath) -> TableItem { return sections[indexPath.section].items[indexPath.row] } + func itemExists(at indexPath: IndexPath) -> Bool { + sections[safe: indexPath.section]?.items[safe: indexPath.row] != nil + } +} + +private extension Collection { + /// Returns the element at the specified index if it is within bounds, otherwise nil. + subscript(safe index: Index) -> Iterator.Element? { + self.existElement(at: index) ? self[index] : nil + } + + /// Returns if exist element at the specified index + func existElement(at index: Index) -> Bool { + indices.contains(index) + } }