Skip to content

Commit 5cd7bfa

Browse files
committed
updated
1 parent fb2c721 commit 5cd7bfa

File tree

6 files changed

+19
-33
lines changed

6 files changed

+19
-33
lines changed

Example/Example.xcodeproj/project.pbxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@
136136
children = (
137137
72AFC23929804B7D00FEA1C8 /* CollectionItem.swift */,
138138
72F99B672A44FBDD00DDDA1E /* SidebarItem.swift */,
139-
72F99B652A44FBCB00DDDA1E /* Section.swift */,
140139
726BE2692D3DB14C00823E9B /* OutlineItem.swift */,
140+
72F99B652A44FBCB00DDDA1E /* Section.swift */,
141141
);
142142
path = Model;
143143
sourceTree = "<group>";

Example/Example/MainViewController.swift

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -77,26 +77,6 @@ class MainViewController: NSViewController {
7777

7878
dataSource.selectElements([galleryItems.first!], scrollPosition: .top)
7979
collectionView.makeFirstResponder()
80-
81-
Swift.print(NSDiffableDataSourceSnapshotReference.classReflection())
82-
var object = dataSource.snapshot() as NSDiffableDataSourceSnapshotReference
83-
object.perform(NSSelectorFromString("reconfigureItemsWithIdentifiers:"), with: [galleryItems[0], galleryItems[1]])
84-
if let impl: NSObject = object.getIvarValue(for: "_impl") {
85-
Swift.print(impl.objectIdentifier)
86-
if let reconfiguredItemIdentifiers = impl.value(forKey: "reconfiguredItemIdentifiers") as? [GalleryItem] {
87-
Swift.print(reconfiguredItemIdentifiers)
88-
}
89-
}
90-
let snapshot = object as NSDiffableDataSourceSnapshot<Section, GalleryItem>
91-
object = snapshot as NSDiffableDataSourceSnapshotReference
92-
if let impl: NSObject = object.getIvarValue(for: "_impl") {
93-
Swift.print(impl.objectIdentifier)
94-
95-
if let reconfiguredItemIdentifiers = impl.value(forKey: "reconfiguredItemIdentifiers") as? [GalleryItem] {
96-
Swift.print(reconfiguredItemIdentifiers)
97-
}
98-
}
99-
10080
}
10181

10282
func applySnapshot(using items: [GalleryItem]) {

Example/Example/Model/OutlineItem.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,19 @@
77

88
import Foundation
99

10-
struct OutlineItem: Hashable, ExpressibleByStringLiteral, CustomStringConvertible {
11-
let title: String
10+
public struct OutlineItem: Hashable, ExpressibleByStringLiteral, CustomStringConvertible {
1211

13-
init(_ title: String) {
12+
public let title: String
13+
14+
public init(_ title: String) {
1415
self.title = title
1516
}
1617

17-
init(stringLiteral value: String) {
18+
public init(stringLiteral value: String) {
1819
self.title = value
1920
}
2021

21-
var description: String {
22+
public var description: String {
2223
title
2324
}
2425
}

Example/Example/Model/SidebarItem.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import Foundation
99

10-
class SidebarItem: NSObject, Identifiable {
10+
public class SidebarItem: NSObject, Identifiable {
1111

1212
public let title: String
1313
public let symbolName: String

Example/Example/OutlineSidebarViewController.swift

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,11 @@ class OutlineSidebarViewController: NSViewController {
1212
typealias DataSource = OutlineViewDiffableDataSource<OutlineItem>
1313
typealias CellRegistration = NSTableView.CellRegistration<NSTableCellView, OutlineItem>
1414

15-
1615
@IBOutlet var outlineView: NSOutlineView!
1716

1817
lazy var dataSource = DataSource(outlineView: outlineView, cellRegistration: cellRegistration)
1918

20-
var currentSnapshot: OutlineViewDiffableDataSourceSnapshot<OutlineItem> {
21-
dataSource.snapshot()
22-
}
23-
24-
lazy var cellRegistration = CellRegistration { tableCell, _, _, outlineItem in
19+
let cellRegistration = CellRegistration { tableCell, _, _, outlineItem in
2520
var configuration = tableCell.defaultContentConfiguration()
2621
configuration.text = outlineItem.title
2722
tableCell.contentConfiguration = configuration

Example/Example/TableSidebarViewController.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,16 @@ class TableSidebarViewController: NSViewController {
4646
/// Enables deleting selected rows via backspace key.
4747
dataSource.deletingHandlers.canDelete = { selectedItems in return selectedItems }
4848

49+
/// Enable dropping strings to the table view by checking if the drop contains strings.
50+
dataSource.droppingHandlers.canDrop = { drop in
51+
return !drop.content.strings.isEmpty
52+
}
53+
54+
/// Provides sidebar items for the dropped strings.
55+
dataSource.droppingHandlers.items = { drop in
56+
return drop.content.strings.compactMap({ SidebarItem($0, symbolName: "photo") })
57+
}
58+
4959
/// Swipe row actions for deleting and favoriting an item.
5060
dataSource.rowActionProvider = { swippedItem, edge in
5161
if edge == .leading {

0 commit comments

Comments
 (0)