Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Examples/SampleApp/SampleApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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";
Expand All @@ -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)";
Expand All @@ -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)";
Expand All @@ -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)";
Expand All @@ -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)";
Expand Down
6 changes: 4 additions & 2 deletions TableViewKit/TableViewKitDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
15 changes: 15 additions & 0 deletions TableViewKit/TableViewManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}