This repository was archived by the owner on Apr 15, 2020. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathTableEditingController.swift
More file actions
64 lines (55 loc) · 2.19 KB
/
TableEditingController.swift
File metadata and controls
64 lines (55 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//
// Created by Jesse Squires
// https://www.jessesquires.com
//
//
// Documentation
// https://jessesquires.github.io/JSQDataSourcesKit
//
//
// GitHub
// https://github.com/jessesquires/JSQDataSourcesKit
//
//
// License
// Copyright © 2015-present Jesse Squires
// Released under an MIT license: https://opensource.org/licenses/MIT
//
import Foundation
import UIKit
/// An instance of `TableEditingController` allows editing a table view via inserting and deleting rows.
public struct TableEditingController<DataSource: DataSourceProtocol> {
// MARK: Typealiases
/// Asks if a row at the specified index path is editable for the specified table view.
/// - Parameters:
/// - item: The item at `indexPath`.
/// - tableView: The table view requesting this information.
/// - indexPath: The index path of the item.
///
/// - Returns: `true` if the specified row is editable, `false` otherwise.
public typealias CanEditRowConfig = (DataSource.Item?, UITableView, IndexPath) -> Bool
/// Commits the editing actions for the specified index path.
///
/// - Parameters:
/// - dataSource: The dataSource at `indexPath`.
/// - tableView: The table view being edited.
/// - commit: The editing style.
/// - indexPath: The index path of the item.
public typealias CommitEditingConfig = (inout DataSource, UITableView, UITableViewCell.EditingStyle, IndexPath) -> Void
/// A closure that determines if a given row is editable.
public let canEditRow: CanEditRowConfig
/// A closure that commits the editing actions for a table view.
public let commitEditing: CommitEditingConfig
// MARK: Initialization
/// Constructs a new `TableEditingController`.
///
/// - Parameters:
/// - canEditRow: The closure that determines if a given row is editable.
/// - commitEditing: The closure that commits the editing actions for a table view.
///
/// - Returns: A new `TableEditingController` instance.
public init(canEditRow: @escaping CanEditRowConfig, commitEditing: @escaping CommitEditingConfig) {
self.canEditRow = canEditRow
self.commitEditing = commitEditing
}
}