Skip to content

Commit 0a3a73c

Browse files
committed
updated
1 parent a7d2b7a commit 0a3a73c

File tree

3 files changed

+17
-19
lines changed

3 files changed

+17
-19
lines changed

Example/Example/TableSidebarViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class TableSidebarViewController: NSViewController {
1616
@IBOutlet var tableView: NSTableView!
1717

1818
lazy var dataSource = DataSource(tableView: tableView, cellRegistration: cellRegistration)
19-
19+
2020
let cellRegistration = CellRegistration { tableCell, _, _, sidebarItem in
2121
/// `defaultContentConfiguration` returns a table cell content configuration with default styling based on the table view it's displayed at (in this case a sidebar table).
2222
var configuration = tableCell.defaultContentConfiguration()

Sources/AdvancedCollectionTableView/Extensions/NSCollectionView/NSCollectionView+DragSessionMove.swift

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,19 @@ extension NSCollectionView {
1515
setAssociatedValue(newValue, key: "draggingSessionMoveHandler")
1616
let selector = #selector(NSCollectionView.draggingSession(_:movedTo:))
1717
if newValue != nil {
18-
guard !isMethodReplaced(selector) else { return }
18+
guard !isMethodHooked(selector) else { return }
1919
do {
20-
try replaceMethod(
21-
selector,
22-
methodSignature: (@convention(c) (AnyObject, Selector, NSDraggingSession, CGPoint) -> ()).self,
23-
hookSignature: (@convention(block) (AnyObject, NSDraggingSession, CGPoint) -> ()).self) { store in {
24-
object, session, point in
25-
(object as? NSCollectionView)?.draggingSessionMoveHandler?(session, point)
26-
store.original(object, selector, session, point)
27-
}
28-
}
20+
try hook(selector, closure: { original, object, sel, session, point in
21+
(object as? NSCollectionView)?.draggingSessionMoveHandler?(session, point)
22+
original(object, sel, session, point)
23+
} as @convention(block) (
24+
(AnyObject, Selector, NSDraggingSession, CGPoint) -> Void,
25+
AnyObject, Selector, NSDraggingSession, CGPoint) -> Void)
2926
} catch {
3027
debugPrint(error)
3128
}
3229
} else {
33-
resetMethod(selector)
30+
revertHooks(for: selector)
3431
}
3532
}
3633
}

Sources/AdvancedCollectionTableView/Extensions/NSTableView/NSTableView+DragSessionMove.swift

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ extension NSTableView {
1414
set {
1515
setAssociatedValue(newValue, key: "draggingSessionMoveHandler")
1616
let selector = #selector(NSTableView.draggingSession(_:movedTo:))
17-
if newValue != nil, !isMethodReplaced(selector) {
17+
if newValue != nil, !isMethodReplaced(selector), !isMethodHooked(selector) {
1818
do {
1919
if responds(to: selector) {
20-
try replaceMethod(selector,
21-
methodSignature: (@convention(c) (AnyObject, Selector, NSDraggingSession, CGPoint) -> ()).self,
22-
hookSignature: (@convention(block) (AnyObject, NSDraggingSession, CGPoint) -> ()).self) { store in { object, session, point in
23-
(object as? NSTableView)?.draggingSessionMovedHandler?(session, point)
24-
store.original(object, selector, session, point)
25-
} }
20+
try hook(selector, closure: { original, object, sel, session, point in
21+
(object as? NSTableView)?.draggingSessionMovedHandler?(session, point)
22+
original(object, sel, session, point)
23+
} as @convention(block) (
24+
(AnyObject, Selector, NSDraggingSession, CGPoint) -> Void,
25+
AnyObject, Selector, NSDraggingSession, CGPoint) -> Void)
2626
} else {
2727
try addMethod(selector,
2828
methodSignature: (@convention(block) (AnyObject, NSDraggingSession, CGPoint) -> ()).self) { object, session, point in
@@ -34,6 +34,7 @@ extension NSTableView {
3434
}
3535
} else if newValue == nil {
3636
resetMethod(selector)
37+
revertHooks(for: selector)
3738
}
3839
}
3940
}

0 commit comments

Comments
 (0)