@@ -53,11 +53,6 @@ public class DataSource: NSObject {
5353 public var willBeginEditing : ( ( RowType , IndexPath ) -> Void ) ? = nil
5454 public var didEndEditing : ( ( IndexPath ? ) -> Void ) ? = nil
5555
56- // MARK: iOS 11
57- //See extension
58- fileprivate var leftSwipeActions : ( ( RowType , IndexPath ) -> Any ? ) ? = nil
59- fileprivate var rightSwipeActions : ( ( RowType , IndexPath ) -> Any ? ) ? = nil
60-
6156 public var sectionHeader : ( ( SectionType , Int ) -> HeaderFooter ) ? = nil
6257 public var sectionFooter : ( ( SectionType , Int ) -> HeaderFooter ) ? = nil
6358
@@ -77,6 +72,10 @@ public class DataSource: NSObject {
7772 public var performAction : ( ( RowType , Selector , Any ? , IndexPath ) -> Void ) ? = nil
7873 public var canFocus : ( ( RowType , IndexPath ) -> Bool ) ? = nil
7974
75+ // MARK: Swipe Actions (iOS 11+ only)
76+ private var _leadingSwipeActions : ( ( RowType , IndexPath ) -> Any ? ) ? = nil
77+ private var _trailingSwipeActions : ( ( RowType , IndexPath ) -> Any ? ) ? = nil
78+
8079 // MARK: UITableViewDataSourcePrefetching
8180
8281 public var prefetchRows : ( ( [ IndexPath ] ) -> Void ) ? = nil
@@ -96,10 +95,48 @@ public class DataSource: NSObject {
9695
9796 public override func responds( to aSelector: Selector ! ) -> Bool {
9897 if super. responds ( to: aSelector) {
98+ if #available( iOS 11 . 0 , * ) {
99+ switch aSelector {
100+ case #selector( UITableViewDelegate . tableView ( _: leadingSwipeActionsConfigurationForRowAt: ) ) :
101+ return isLeadingSwipeActionsImplemented ? true : fallbackDelegateResponds ( to: aSelector)
102+ case #selector( UITableViewDelegate . tableView ( _: trailingSwipeActionsConfigurationForRowAt: ) ) :
103+ return isTrailingSwipeActionsImplemented ? true : fallbackDelegateResponds ( to: aSelector)
104+ default :
105+ return true
106+ }
107+ } else {
108+ return true
109+ }
110+ }
111+
112+ return fallbackDelegateResponds ( to: aSelector)
113+ }
114+
115+ private func fallbackDelegateResponds( to aSelector: Selector ! ) -> Bool {
116+ let result = fallbackDelegate? . responds ( to: aSelector) ?? false
117+
118+ print ( aSelector)
119+ print ( result)
120+
121+ return result
122+ }
123+
124+ @available ( iOS 11 . 0 , * )
125+ private var isLeadingSwipeActionsImplemented : Bool {
126+ if _leadingSwipeActions != nil {
99127 return true
100- } else {
101- return fallbackDelegate? . responds ( to: aSelector) ?? false
102128 }
129+
130+ return cellDescriptors. values. contains ( where: { ( $0 as? CellDescriptorTypeiOS11 ) ? . leadingSwipeActionsClosure != nil } )
131+ }
132+
133+ @available ( iOS 11 . 0 , * )
134+ private var isTrailingSwipeActionsImplemented : Bool {
135+ if _trailingSwipeActions != nil {
136+ return true
137+ }
138+
139+ return cellDescriptors. values. contains ( where: { ( $0 as? CellDescriptorTypeiOS11 ) ? . trailingSwipeActionsClosure != nil } )
103140 }
104141
105142 // MARK: Additional
@@ -309,23 +346,31 @@ public class DataSource: NSObject {
309346extension DataSource {
310347 public var leadingSwipeActions : ( ( RowType , IndexPath ) -> UISwipeActionsConfiguration ? ) ? {
311348 get {
349+ if _leadingSwipeActions == nil {
350+ return nil
351+ }
352+
312353 return { [ weak self] ( rowType, indexPath) in
313- return self ? . leftSwipeActions ? ( rowType, indexPath) as? UISwipeActionsConfiguration
354+ return self ? . _leadingSwipeActions ? ( rowType, indexPath) as? UISwipeActionsConfiguration
314355 }
315356 }
316357 set {
317- leftSwipeActions = newValue
358+ _leadingSwipeActions = newValue
318359 }
319360 }
320361
321362 public var trailingSwipeActions : ( ( RowType , IndexPath ) -> UISwipeActionsConfiguration ? ) ? {
322363 get {
364+ if _trailingSwipeActions == nil {
365+ return nil
366+ }
367+
323368 return { [ weak self] ( rowType, indexPath) in
324- return self ? . rightSwipeActions ? ( rowType, indexPath) as? UISwipeActionsConfiguration
369+ return self ? . _trailingSwipeActions ? ( rowType, indexPath) as? UISwipeActionsConfiguration
325370 }
326371 }
327372 set {
328- rightSwipeActions = newValue
373+ _trailingSwipeActions = newValue
329374 }
330375 }
331376
0 commit comments