├── .gitignore ├── Diffable Data Source ├── NSOutlineView+Snapshot.swift ├── OutlineViewDataSource+Passthrough.swift ├── OutlineViewDiffableDataSource.h ├── OutlineViewDiffableDataSource.swift ├── OutlineViewSnapshot.swift ├── OutlineViewSnapshotMember.swift └── PassthroughWrappers.swift ├── Info.plist ├── LICENSE ├── OutlineTest ├── AppDelegate.swift ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── Contents.json ├── Base.lproj │ └── Main.storyboard ├── Info.plist ├── OutlineTest.entitlements ├── ReorderableArrayDataSource.swift └── ViewController.swift ├── OutlineTestTests ├── Info.plist └── OutlineTestTests.swift ├── OutlineViewDiffableDataSource.xcodeproj ├── project.pbxproj └── project.xcworkspace │ └── contents.xcworkspacedata ├── OutlineViewDiffableDataSourceTests ├── ArrayDataSource.swift ├── Info.plist ├── OutlineViewDiffableDataSourceTests.swift └── OutlineViewSnapshotTests.swift ├── README.md └── diff.gif /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## User settings 6 | xcuserdata/ 7 | 8 | ## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9) 9 | *.xcscmblueprint 10 | *.xccheckout 11 | 12 | ## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4) 13 | build/ 14 | DerivedData/ 15 | *.moved-aside 16 | *.pbxuser 17 | !default.pbxuser 18 | *.mode1v3 19 | !default.mode1v3 20 | *.mode2v3 21 | !default.mode2v3 22 | *.perspectivev3 23 | !default.perspectivev3 24 | 25 | ## Obj-C/Swift specific 26 | *.hmap 27 | 28 | ## App packaging 29 | *.ipa 30 | *.dSYM.zip 31 | *.dSYM 32 | 33 | ## Playgrounds 34 | timeline.xctimeline 35 | playground.xcworkspace 36 | 37 | # Swift Package Manager 38 | # 39 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. 40 | # Packages/ 41 | # Package.pins 42 | # Package.resolved 43 | # *.xcodeproj 44 | # 45 | # Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata 46 | # hence it is not needed unless you have added a package configuration file to your project 47 | # .swiftpm 48 | 49 | .build/ 50 | 51 | # CocoaPods 52 | # 53 | # We recommend against adding the Pods directory to your .gitignore. However 54 | # you should judge for yourself, the pros and cons are mentioned at: 55 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 56 | # 57 | # Pods/ 58 | # 59 | # Add this line if you want to avoid checking in source code from the Xcode workspace 60 | # *.xcworkspace 61 | 62 | # Carthage 63 | # 64 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 65 | # Carthage/Checkouts 66 | 67 | Carthage/Build/ 68 | 69 | # Accio dependency management 70 | Dependencies/ 71 | .accio/ 72 | 73 | # fastlane 74 | # 75 | # It is recommended to not store the screenshots in the git repo. 76 | # Instead, use fastlane to re-generate the screenshots whenever they are needed. 77 | # For more information about the recommended setup visit: 78 | # https://docs.fastlane.tools/best-practices/source-control/#source-control 79 | 80 | fastlane/report.xml 81 | fastlane/Preview.html 82 | fastlane/screenshots/**/*.png 83 | fastlane/test_output 84 | 85 | # Code Injection 86 | # 87 | # After new code Injection tools there's a generated folder /iOSInjectionProject 88 | # https://github.com/johnno1962/injectionforxcode 89 | 90 | iOSInjectionProject/ 91 | -------------------------------------------------------------------------------- /Diffable Data Source/NSOutlineView+Snapshot.swift: -------------------------------------------------------------------------------- 1 | // 2 | // NSOutlineView+Snapshot.swift 3 | // OutlineViewDiffableDataSource 4 | // 5 | // Created by Steve Sparks on 2/8/20. 6 | // Copyright © 2020 Big Nerd Ranch. All rights reserved. 7 | // 8 | 9 | import Cocoa 10 | 11 | // Turn a diff into commands 12 | extension NSOutlineView { 13 | func apply(_ snapshot: OutlineViewSnapshotDiff, with animation: NSTableView.AnimationOptions = [.effectFade]) { 14 | beginUpdates() 15 | snapshot.forEach { instr in 16 | switch instr { 17 | case .insert(_, let indexPath): 18 | let parent = lastParent(for: indexPath) 19 | if let childIndex = indexPath.last { 20 | insertItems(at: [childIndex], inParent: parent, withAnimation: animation) 21 | } 22 | case .move(let src, let dst): 23 | let srcParent = lastParent(for: src) 24 | let dstParent = lastParent(for: dst) 25 | 26 | if let srcChild = src.last, let dstChild = dst.last { 27 | moveItem(at: srcChild, inParent: srcParent, to: dstChild, inParent: dstParent) 28 | } 29 | case .remove(_, let indexPath): 30 | let parent = lastParent(for: indexPath) 31 | if let childIndex = indexPath.last { 32 | removeItems(at: [childIndex], inParent: parent, withAnimation: animation) 33 | } 34 | } 35 | } 36 | endUpdates() 37 | } 38 | 39 | func lastParent(for indexPath: IndexPath) -> Any? { 40 | var parent: Any? 41 | 42 | var ip = indexPath 43 | ip.removeLast() 44 | 45 | for index in ip { 46 | if let g = child(index, ofItem: parent) { 47 | parent = g 48 | } 49 | } 50 | return parent 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Diffable Data Source/OutlineViewDataSource+Passthrough.swift: -------------------------------------------------------------------------------- 1 | // 2 | // OutlineViewDataSource+Passthrough.swift 3 | // OutlineViewDiffableDataSource 4 | // 5 | // Created by Steve Sparks on 2/9/20. 6 | // Copyright © 2020 Big Nerd Ranch. All rights reserved. 7 | // 8 | 9 | import Cocoa 10 | 11 | public extension NSObject { 12 | } 13 | 14 | public class PassthroughOutlineViewDataSource: NSObject, NSOutlineViewDataSource, NSOutlineViewDelegate { 15 | func report(_ message: String = "", _ preamble: String = "", function: String = #function) { 16 | // let fn = String(describing: type(of: self)) 17 | // print("--> \(preamble)\(fn) \(function) \(message) ") 18 | } 19 | 20 | var dataSource: NSOutlineViewDataSource! 21 | var delegate: NSOutlineViewDelegate? 22 | 23 | init(dataSource: NSOutlineViewDataSource, delegate: NSOutlineViewDelegate? = nil) { 24 | self.dataSource = dataSource 25 | self.delegate = delegate 26 | super.init() 27 | } 28 | 29 | enum OverriddenSelectors: String, CaseIterable { 30 | case outlineViewNumberOfChildrenOfItem = "outlineView:numberOfChildrenOfItem:" 31 | case outlineViewChildOfItem = "outlineView:child:ofItem:" 32 | case outlineViewIsItemExpandable = "outlineView:isItemExpandable:" 33 | } 34 | 35 | enum DataSourceSelectors: String, CaseIterable { 36 | case outlineViewPersistentObjectForItem = "outlineView:persistentObjectForItem:" 37 | case outlineViewItemForPersistentObject = "outlineView:itemForPersistentObject:" 38 | case outlineViewObjectValueForByItem = "outlineView:objectValueForTableColumn:byItem:" 39 | case outlineViewSetObjectValueForByItem = "outlineView:setObjectValue:forTableColumn:byItem:" 40 | case outlineViewSortDescriptorsDidChange = "outlineView:sortDescriptorsDidChange:" 41 | case outlineViewUpdateDraggingItemsForDrag = "outlineView:updateDraggingItemsForDrag:" 42 | case outlineViewPasteboardWriterForItem = "outlineView:pasteboardWriterForItem:" 43 | case outlineViewWriteItemsTo = "outlineView:writeItems:to:" 44 | case outlineViewValidateDrop = "outlineView:validateDrop:proposedItem:proposedChildIndex:" 45 | case outlineViewAcceptDrop = "outlineView:acceptDrop:item:childIndex:" 46 | case outlineViewDraggingBegin = "outlineView:draggingSession:willBeginAt:forItems:" 47 | case outlineViewDraggingEnd = "outlineView:draggingEndedAt:operation:" 48 | } 49 | 50 | enum DelegateSelectors: String, CaseIterable { 51 | case outlineViewColumnDidMove = "outlineViewColumnDidMove:" 52 | case outlineViewIsGroupItem = "outlineView:isGroupItem:" 53 | case outlineViewDidClick = "outlineView:didClick:" 54 | case outlineViewDidDrag = "outlineView:didDrag:" 55 | case outlineViewMouseDownInHeaderOf = "outlineView:mouseDownInHeaderOf:" 56 | case outlineViewShouldExpandItem = "outlineView:shouldExpandItem:" 57 | case outlineViewShouldCollapseItem = "outlineView:shouldCollapseItem:" 58 | case outlineViewShouldSelectItem = "outlineView:shouldSelectItem:" 59 | case outlineViewShouldSelectTableColumn = "outlineView:shouldSelect:" 60 | case outlineViewShouldEditTableColumn = "outlineView:shouldEdit:item:" 61 | case outlineViewViewForTableColumnItem = "outlineView:viewForTableColumn:item:" 62 | case outlineViewItemWillExpand = "outlineViewItemWillExpand:" 63 | case outlineViewItemWillCollapse = "outlineViewItemWillCollapse:" 64 | case outlineViewItemDidExpand = "outlineViewItemDidExpand:" 65 | case outlineViewItemDidCollapse = "outlineViewItemDidCollapse:" 66 | case outlineViewWillDisplayCellForTableColumnItem = "outlineView:willDisplayCell:forTableColumn:item:" 67 | case outlineViewWillDisplayOutlineCellForTableColumnItem = "outlineView:willDisplayOutlineCell:forTableColumn:item:" 68 | } 69 | 70 | override public func responds(to aSelector: Selector!) -> Bool { 71 | let sel = aSelector.description 72 | var ret = false 73 | var ident = "???" 74 | 75 | if let _ = OverriddenSelectors(rawValue: sel) { 76 | ident = "OVR" 77 | ret = true 78 | } else if let _ = DataSourceSelectors(rawValue: sel) { 79 | ident = "DS " 80 | ret = dataSource.responds(to: aSelector) 81 | } else if let _ = DelegateSelectors(rawValue: sel) { 82 | ident = "DLG" 83 | ret = delegate?.responds(to: aSelector) ?? false 84 | } else { 85 | ret = super.responds(to: aSelector) 86 | } 87 | 88 | // change this to print() if you wish 89 | _ = "\(ident) \(sel) -> \(ret)" 90 | return ret 91 | } 92 | 93 | public func outlineView(_ outlineView: NSOutlineView, numberOfChildrenOfItem item: Any?) -> Int { 94 | report() 95 | return dataSource.outlineView!(outlineView, numberOfChildrenOfItem: item) 96 | } 97 | 98 | public func outlineView(_ outlineView: NSOutlineView, child index: Int, ofItem item: Any?) -> Any { 99 | report() 100 | return dataSource.outlineView!(outlineView, child: index, ofItem: item) 101 | } 102 | 103 | public func outlineView(_ outlineView: NSOutlineView, isItemExpandable item: Any) -> Bool { 104 | report() 105 | return dataSource.outlineView!(outlineView, isItemExpandable: item) 106 | } 107 | 108 | //// 109 | 110 | public func outlineView(_ outlineView: NSOutlineView, persistentObjectForItem item: Any?) -> Any? { 111 | report() 112 | return dataSource.outlineView!(outlineView, persistentObjectForItem: item) 113 | } 114 | 115 | public func outlineView(_ outlineView: NSOutlineView, itemForPersistentObject object: Any) -> Any? { 116 | report() 117 | return dataSource.outlineView!(outlineView, itemForPersistentObject: object) 118 | } 119 | 120 | public func outlineView(_ outlineView: NSOutlineView, objectValueFor tableColumn: NSTableColumn?, byItem item: Any?) -> Any? { 121 | report() 122 | return dataSource.outlineView!(outlineView, objectValueFor: tableColumn, byItem: item) 123 | } 124 | 125 | public func outlineView(_ outlineView: NSOutlineView, setObjectValue object: Any?, for tableColumn: NSTableColumn?, byItem item: Any?) { 126 | report() 127 | dataSource.outlineView!(outlineView, setObjectValue: object, for: tableColumn, byItem: item) 128 | } 129 | 130 | public func outlineView(_ outlineView: NSOutlineView, sortDescriptorsDidChange oldDescriptors: [NSSortDescriptor]) { 131 | report() 132 | dataSource.outlineView!(outlineView, sortDescriptorsDidChange: oldDescriptors) 133 | } 134 | 135 | public func outlineView(_ outlineView: NSOutlineView, updateDraggingItemsForDrag draggingInfo: NSDraggingInfo) { 136 | report() 137 | dataSource.outlineView!(outlineView, updateDraggingItemsForDrag: draggingInfo) 138 | } 139 | 140 | public func outlineView(_ outlineView: NSOutlineView, pasteboardWriterForItem item: Any) -> NSPasteboardWriting? { 141 | report() 142 | return dataSource.outlineView?(outlineView, pasteboardWriterForItem: item) 143 | } 144 | 145 | public func outlineView(_ outlineView: NSOutlineView, writeItems items: [Any], to pasteboard: NSPasteboard) -> Bool { 146 | report() 147 | return dataSource.outlineView!(outlineView, writeItems: items, to: pasteboard) 148 | } 149 | 150 | public func outlineView(_ outlineView: NSOutlineView, validateDrop info: NSDraggingInfo, proposedItem item: Any?, proposedChildIndex index: Int) -> NSDragOperation { 151 | report() 152 | return dataSource.outlineView?(outlineView, validateDrop: info, proposedItem: item, proposedChildIndex: index) ?? .generic 153 | } 154 | 155 | public func outlineView(_ outlineView: NSOutlineView, acceptDrop info: NSDraggingInfo, item: Any?, childIndex index: Int) -> Bool { 156 | report() 157 | return dataSource.outlineView?(outlineView, acceptDrop: info, item: item, childIndex: index) ?? false 158 | } 159 | 160 | public func outlineView(_ outlineView: NSOutlineView, draggingSession session: NSDraggingSession, willBeginAt screenPoint: NSPoint, forItems draggedItems: [Any]) { 161 | report() 162 | dataSource.outlineView?(outlineView, draggingSession: session, willBeginAt: screenPoint, forItems: draggedItems) 163 | } 164 | 165 | public func outlineView(_ outlineView: NSOutlineView, draggingSession session: NSDraggingSession, endedAt screenPoint: NSPoint, operation: NSDragOperation) { 166 | report() 167 | dataSource.outlineView?(outlineView, draggingSession: session, endedAt: screenPoint, operation: operation) 168 | } 169 | 170 | // MARK: - NSOutlineViewDelegate 171 | 172 | public func outlineViewColumnDidMove(_ notification: Notification) { 173 | report() 174 | delegate!.outlineViewColumnDidMove?(notification) 175 | } 176 | 177 | public func outlineView(_ outlineView: NSOutlineView, isGroupItem item: Any) -> Bool { 178 | report() 179 | return delegate!.outlineView!(outlineView, isGroupItem: item) 180 | } 181 | 182 | public func outlineView(_ outlineView: NSOutlineView, didClick tableColumn: NSTableColumn) { 183 | report() 184 | delegate!.outlineView!(outlineView, didClick: tableColumn) 185 | } 186 | 187 | public func outlineView(_ outlineView: NSOutlineView, didDrag tableColumn: NSTableColumn) { 188 | report() 189 | delegate!.outlineView!(outlineView, didDrag: tableColumn) 190 | } 191 | 192 | public func outlineView(_ outlineView: NSOutlineView, mouseDownInHeaderOf tableColumn: NSTableColumn) { 193 | report() 194 | delegate!.outlineView!(outlineView, mouseDownInHeaderOf: tableColumn) 195 | } 196 | 197 | public func outlineView(_ outlineView: NSOutlineView, shouldExpandItem item: Any) -> Bool { 198 | report() 199 | return delegate!.outlineView!(outlineView, shouldExpandItem: item) 200 | } 201 | 202 | public func outlineView(_ outlineView: NSOutlineView, shouldSelectItem item: Any) -> Bool { 203 | report() 204 | return delegate!.outlineView!(outlineView, shouldSelectItem: item) 205 | } 206 | 207 | public func outlineView(_ outlineView: NSOutlineView, shouldCollapseItem item: Any) -> Bool { 208 | report() 209 | return delegate!.outlineView!(outlineView, shouldCollapseItem: item) 210 | } 211 | 212 | public func outlineView(_ outlineView: NSOutlineView, shouldSelect tableColumn: NSTableColumn?) -> Bool { 213 | report() 214 | return delegate!.outlineView!(outlineView, shouldSelect: tableColumn) 215 | } 216 | 217 | public func outlineView(_ outlineView: NSOutlineView, shouldEdit tableColumn: NSTableColumn?, item: Any) -> Bool { 218 | report() 219 | return delegate!.outlineView!(outlineView, shouldEdit: tableColumn, item: item) 220 | } 221 | 222 | public func outlineViewItemWillCollapse(_ notification: Notification) { 223 | report() 224 | delegate!.outlineViewItemWillCollapse!(notification) 225 | } 226 | 227 | public func outlineViewItemWillExpand(_ notification: Notification) { 228 | report() 229 | delegate!.outlineViewItemWillExpand!(notification) 230 | } 231 | 232 | public func outlineViewItemDidCollapse(_ notification: Notification) { 233 | report() 234 | delegate!.outlineViewItemDidCollapse!(notification) 235 | } 236 | 237 | public func outlineViewItemDidExpand(_ notification: Notification) { 238 | report() 239 | delegate!.outlineViewItemDidExpand!(notification) 240 | } 241 | public func outlineView(_ outlineView: NSOutlineView, viewFor tableColumn: NSTableColumn?, item: Any) -> NSView? { 242 | report() 243 | return delegate!.outlineView!(outlineView, viewFor: tableColumn, item: item) ?? nil 244 | } 245 | // MARK: - To Do 246 | // TODO: Implement the loop: 247 | // - contrive a use of the method 248 | // - note the selector logged in `responds(to:)` 249 | // - add the selector to the DelegateSelectors array 250 | // - uncomment the method down below 251 | // - correct the code as necessary 252 | // 253 | // public func outlineView(_ outlineView: NSOutlineView, shouldShowCellExpansionFor tableColumn: NSTableColumn?, item: Any) -> Bool { 254 | // report() 255 | // return delegate!.outlineView!(outlineView, shouldShowCellExpansionFor: tableColumn, item: item) ?? false 256 | // } 257 | // public func outlineView(_ outlineView: NSOutlineView, shouldReorderColumn columnIndex: Int, toColumn newColumnIndex: Int) -> Bool { 258 | // report() 259 | // return delegate!.outlineView!(outlineView, shouldReorderColumn: columnIndex, toColumn: newColumnIndex) ?? false 260 | // } 261 | // public func outlineView(_ outlineView: NSOutlineView, heightOfRowByItem item: Any) -> CGFloat { 262 | // report() 263 | // return delegate!.outlineView!(outlineView, heightOfRowByItem: item) ?? 264 | // delegate!.outlineView!(outlineView, viewFor: nil, item: item)?.fittingSize.height ?? 265 | // 16.0 266 | // } 267 | // public func outlineView(_ outlineView: NSOutlineView, sizeToFitWidthOfColumn column: Int) -> CGFloat { 268 | // report() 269 | // return delegate!.outlineView!(outlineView, sizeToFitWidthOfColumn: column) ?? 0.0 270 | // } 271 | // public func outlineView(_ outlineView: NSOutlineView, rowViewForItem item: Any) -> NSTableRowView? { 272 | // report() 273 | // return delegate!.outlineView!(outlineView, rowViewForItem: item) ?? nil 274 | // } 275 | // public func outlineView(_ outlineView: NSOutlineView, dataCellFor tableColumn: NSTableColumn?, item: Any) -> NSCell? { 276 | // report() 277 | // return delegate!.outlineView!(outlineView, dataCellFor: tableColumn, item: item) ?? nil 278 | // } 279 | // public func outlineView(_ outlineView: NSOutlineView, typeSelectStringFor tableColumn: NSTableColumn?, item: Any) -> String? { 280 | // report() 281 | // return delegate!.outlineView!(outlineView, typeSelectStringFor: tableColumn, item: item) ?? nil 282 | // } 283 | // public func outlineView(_ outlineView: NSOutlineView, shouldShowOutlineCellForItem item: Any) -> Bool { 284 | // report() 285 | // return delegate!.outlineView!(outlineView, shouldShowOutlineCellForItem: item) ?? false 286 | // } 287 | // 288 | // public func outlineView(_ outlineView: NSOutlineView, didAdd rowView: NSTableRowView, forRow row: Int) { 289 | // report() 290 | // } 291 | // public func outlineView(_ outlineView: NSOutlineView, didRemove rowView: NSTableRowView, forRow row: Int) { 292 | // report() 293 | // } 294 | // 295 | // public func outlineView(_ outlineView: NSOutlineView, willDisplayCell cell: Any, for tableColumn: NSTableColumn?, item: Any) { 296 | // report() 297 | // } 298 | // public func outlineView(_ outlineView: NSOutlineView, willDisplayOutlineCell cell: Any, for tableColumn: NSTableColumn?, item: Any) { 299 | // report() 300 | // } 301 | // public func outlineView(_ outlineView: NSOutlineView, shouldTrackCell cell: NSCell, for tableColumn: NSTableColumn?, item: Any) -> Bool { 302 | // report() 303 | // } 304 | // public func outlineView(_ outlineView: NSOutlineView, selectionIndexesForProposedSelection proposedSelectionIndexes: IndexSet) -> IndexSet { 305 | // report() 306 | // } 307 | // public func outlineView(_ outlineView: NSOutlineView, shouldTypeSelectFor event: NSEvent, withCurrentSearch searchString: String?) -> Bool { 308 | // report() 309 | // } 310 | // public func outlineView(_ outlineView: NSOutlineView, nextTypeSelectMatchFromItem startItem: Any, toItem endItem: Any, for searchString: String) -> Any? { 311 | // report() 312 | // } 313 | // public func outlineView(_ outlineView: NSOutlineView, toolTipFor cell: NSCell, rect: NSRectPointer, tableColumn: NSTableColumn?, item: Any, mouseLocation: NSPoint) -> String { 314 | // report() 315 | // } 316 | // public func selectionShouldChange(in outlineView: NSOutlineView) -> Bool { 317 | // report() 318 | // } 319 | } 320 | 321 | -------------------------------------------------------------------------------- /Diffable Data Source/OutlineViewDiffableDataSource.h: -------------------------------------------------------------------------------- 1 | // 2 | // OutlineViewDiffableDataSource.h 3 | // OutlineViewDiffableDataSource 4 | // 5 | // Created by Steve Sparks on 2/8/20. 6 | // Copyright © 2020 Big Nerd Ranch. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | //! Project version number for OutlineViewDiffableDataSource. 12 | FOUNDATION_EXPORT double OutlineViewDiffableDataSourceVersionNumber; 13 | 14 | //! Project version string for OutlineViewDiffableDataSource. 15 | FOUNDATION_EXPORT const unsigned char OutlineViewDiffableDataSourceVersionString[]; 16 | 17 | // In this header, you should import all the public headers of your framework using statements like #import 18 | 19 | 20 | -------------------------------------------------------------------------------- /Diffable Data Source/OutlineViewDiffableDataSource.swift: -------------------------------------------------------------------------------- 1 | // 2 | // OutlineViewDiffableDataSource.swift 3 | // OutlineViewDiffableDataSource 4 | // 5 | // Created by Steve Sparks on 2/8/20. 6 | // Copyright © 2020 Big Nerd Ranch. All rights reserved. 7 | // 8 | 9 | import Cocoa 10 | 11 | /*** 12 | * Created by Steve Sparks for Big Nerd Ranch 13 | * 14 | * I saw a demo of UITableViewDiffableDataSource and loved it. I was working on a 15 | * large Mac app with a complex NSOutlineView. Each time the contents of the outline 16 | * view changed, we were reloading, and had a TON of plumbing around hiding that fact. 17 | */ 18 | public class OutlineViewDiffableDataSource: PassthroughOutlineViewDataSource { 19 | private let outlineView: NSOutlineView! 20 | 21 | public init(baseDataSource: NSOutlineViewDataSource, targetView: NSOutlineView, delegate: NSOutlineViewDelegate? = nil) { 22 | self.outlineView = targetView 23 | super.init(dataSource: baseDataSource, delegate: delegate) 24 | snapshot = OutlineViewSnapshot(from: dataSource, for: outlineView) 25 | targetView.dataSource = self 26 | } 27 | 28 | private var snapshot = OutlineViewSnapshot() 29 | 30 | // Use when the model has changed and you want animation 31 | public func applySnapshot() { 32 | guard Thread.current == Thread.main else { 33 | DispatchQueue.main.async { self.applySnapshot() } 34 | return 35 | } 36 | 37 | let oldSnapshot = snapshot 38 | guard !oldSnapshot.isEmpty else { 39 | refreshSnapshot() 40 | outlineView.reloadData() 41 | return 42 | } 43 | 44 | refreshSnapshot() 45 | let newSnapshot = snapshot 46 | outlineView.apply(oldSnapshot.instructions(forMorphingInto: newSnapshot)) 47 | } 48 | 49 | public func refreshSnapshot() { 50 | snapshot = OutlineViewSnapshot(from: dataSource, for: outlineView) 51 | } 52 | 53 | var isEmpty: Bool { 54 | return snapshot.isEmpty 55 | } 56 | 57 | override public func outlineView(_ outlineView: NSOutlineView, numberOfChildrenOfItem item: Any?) -> Int { 58 | guard let item = item as? T? else { 59 | return 0 60 | } 61 | let ret = snapshot.numberOfChildren(ofItem: item) 62 | return ret 63 | } 64 | 65 | override public func outlineView(_ outlineView: NSOutlineView, child index: Int, ofItem item: Any?) -> Any { 66 | if item == nil { return snapshot.child(index, ofItem: nil) ?? "" } 67 | 68 | guard let item = item as? T? else { 69 | return "" 70 | } 71 | let ret = snapshot.child(index, ofItem: item) 72 | return ret ?? "" 73 | } 74 | 75 | override public func outlineView(_ outlineView: NSOutlineView, isItemExpandable item: Any) -> Bool { 76 | guard let item = item as? T else { 77 | return false 78 | } 79 | let ret = snapshot.isItemExpandable(item) 80 | return ret 81 | } 82 | 83 | // Makes snapshots animate in and out 84 | public override func outlineView(_ outlineView: NSOutlineView, draggingSession session: NSDraggingSession, willBeginAt screenPoint: NSPoint, forItems draggedItems: [Any]) { 85 | super.outlineView(outlineView, draggingSession: session, willBeginAt: screenPoint, forItems: draggedItems) 86 | // applySnapshot() 87 | } 88 | 89 | public override func outlineView(_ outlineView: NSOutlineView, draggingSession session: NSDraggingSession, endedAt screenPoint: NSPoint, operation: NSDragOperation) { 90 | super.outlineView(outlineView, draggingSession: session, endedAt: screenPoint, operation: operation) 91 | applySnapshot() 92 | } 93 | } 94 | 95 | // Everything passes through. 96 | -------------------------------------------------------------------------------- /Diffable Data Source/OutlineViewSnapshot.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Snapshot.swift 3 | // OutlineViewDiffableDataSource 4 | // 5 | // Created by Steve Sparks on 2/8/20. 6 | // Copyright © 2020 Big Nerd Ranch. All rights reserved. 7 | // 8 | 9 | import Cocoa 10 | 11 | public class OutlineViewSnapshot: NSObject { 12 | private var root: OutlineViewSnapshotMember 13 | 14 | init(from ds: NSOutlineViewDataSource, for view: NSOutlineView) { 15 | root = OutlineViewSnapshot.member(using: ds, in: view) 16 | super.init() 17 | } 18 | 19 | override init() { 20 | root = OutlineViewSnapshotMember() 21 | super.init() 22 | } 23 | 24 | var isEmpty: Bool { return root.children.isEmpty } 25 | 26 | private static func member(for item: T? = nil, using ds: NSOutlineViewDataSource, in view: NSOutlineView, recursive: Bool = true) -> OutlineViewSnapshotMember { 27 | let itemCount = ds.outlineView?(view, numberOfChildrenOfItem: item) ?? 0 28 | var children = [OutlineViewSnapshotMember]() 29 | if recursive && itemCount > 0 { 30 | (0..) -> OutlineViewSnapshotMember? { 51 | return root.parent(of: member) 52 | } 53 | 54 | func instructions(forMorphingInto destination: OutlineViewSnapshot) -> OutlineViewSnapshotDiff { 55 | var raw = root.instructions(forMorphingInto: destination.root, from: IndexPath()) 56 | raw.reduce() 57 | return raw 58 | } 59 | 60 | func numberOfChildren(ofItem item: T?) -> Int { 61 | if let item = item { 62 | if let member = root.search(for: item) { 63 | return member.children.count 64 | } 65 | } else { 66 | return root.children.count 67 | } 68 | return 0 69 | } 70 | 71 | func child(_ index: Int, ofItem item: T?) -> T? { 72 | if let item = item { 73 | if let member = root.search(for: item) { 74 | return member.children[index].item 75 | } 76 | } else { 77 | return root.children[index].item 78 | } 79 | return nil 80 | } 81 | 82 | func isItemExpandable(_ item: T) -> Bool { 83 | if let member = root.search(for: item) { 84 | return member.isExpandable 85 | } 86 | return false 87 | } 88 | } 89 | 90 | extension OutlineViewSnapshotDiff { 91 | mutating func reduce() { 92 | // search for all removed, then try to pair with an inserted 93 | let removeds = allRemoved 94 | for removed in removeds { 95 | let inserteds = allInserted 96 | if let item = removed.item, 97 | let inserted = inserteds.first(where: { $0.item == item }) { 98 | let newInstruction = OutlineChangeInstruction.move(removed.targetIndexPath, inserted.targetIndexPath) 99 | delete(removed) 100 | guard let insertIdx = firstIndex(where: { $0 == inserted }) else { 101 | preconditionFailure("how does this happen") 102 | } 103 | insert(newInstruction, at: insertIdx) 104 | } 105 | } 106 | } 107 | 108 | mutating func delete(_ item: OutlineChangeInstruction) { 109 | if let removeIdx = firstIndex(where: { $0 == item }) { 110 | remove(at: removeIdx) 111 | } 112 | } 113 | var allRemoved: [OutlineChangeInstruction] { 114 | return self.filter { if case OutlineChangeInstruction.remove = $0 { return true } else { return false } } 115 | } 116 | var allInserted: [OutlineChangeInstruction] { 117 | return self.filter { if case OutlineChangeInstruction.insert = $0 { return true } else { return false } } 118 | } 119 | } 120 | 121 | extension OutlineChangeInstruction: Equatable { 122 | public static func ==(lhs: OutlineChangeInstruction, rhs: OutlineChangeInstruction) -> Bool { 123 | switch (lhs, rhs) { 124 | case (.insert(let l, let l2), .insert(let r, let r2)): return l == r && l2 == r2 125 | case (.remove(let l, let l2), .remove(let r, let r2)): return l == r && l2 == r2 126 | case (.move(let l, let l2), .move(let r, let r2)): return l == r && l2 == r2 127 | default: break 128 | } 129 | 130 | return false 131 | } 132 | 133 | var item: AnyHashable? { 134 | switch self { 135 | case .remove(let item, _): return item 136 | case .insert(let item, _): return item 137 | default: return nil 138 | } 139 | } 140 | 141 | var targetIndexPath: IndexPath { 142 | switch self { 143 | case .remove(_, let indexPath): return indexPath 144 | case .insert(_, let indexPath): return indexPath 145 | case .move(_, let indexPath): return indexPath 146 | } 147 | } 148 | } 149 | -------------------------------------------------------------------------------- /Diffable Data Source/OutlineViewSnapshotMember.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SnapshotMember.swift 3 | // OutlineViewDiffableDataSource 4 | // 5 | // Created by Steve Sparks on 2/8/20. 6 | // Copyright © 2020 Big Nerd Ranch. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | /* This represents a node in the outline data source. 12 | * It has answers to the three basic questions about the node. 13 | */ 14 | internal struct OutlineViewSnapshotMember { 15 | var item: T? 16 | var children: [OutlineViewSnapshotMember] = [] 17 | var isExpandable = false 18 | 19 | func indexPath(of member: OutlineViewSnapshotMember) -> IndexPath? { 20 | for (idx, child) in children.enumerated() { 21 | if child == member { 22 | return IndexPath(indexes: [idx]) 23 | } else if let childIP = child.indexPath(of: member) { 24 | return IndexPath(indexes: [idx]).appending(childIP) 25 | } 26 | } 27 | return nil 28 | } 29 | 30 | func parent(of member: OutlineViewSnapshotMember) -> OutlineViewSnapshotMember? { 31 | for child in children { 32 | if child == member { return self } 33 | if let p = child.parent(of: member) { return p } 34 | } 35 | return nil 36 | } 37 | 38 | func search(for item: T) -> OutlineViewSnapshotMember? { 39 | if item == self.item { return self } 40 | for child in children { 41 | if let hit = child.search(for: item) { 42 | return hit 43 | } 44 | } 45 | return nil 46 | } 47 | } 48 | 49 | extension OutlineViewSnapshotMember: CustomStringConvertible { 50 | var description: String { 51 | let thing: Any = item ?? "-nil-" 52 | return "" 53 | } 54 | } 55 | 56 | extension OutlineViewSnapshotMember: Equatable, Hashable { 57 | static func ==(lhs: OutlineViewSnapshotMember, rhs: OutlineViewSnapshotMember) -> Bool { 58 | return lhs.item == rhs.item 59 | } 60 | 61 | func hash(into hasher: inout Hasher) { 62 | item.hash(into: &hasher) 63 | } 64 | } 65 | 66 | public enum OutlineChangeInstruction: CustomStringConvertible { 67 | case remove(AnyHashable, IndexPath) 68 | case insert(AnyHashable, IndexPath) 69 | case move(IndexPath, IndexPath) 70 | 71 | public var description: String { 72 | switch self { 73 | case .remove(let idx): return "Removing @ \(idx)" 74 | case .insert(let item, let idx): return "Inserting @ \(idx): \(item)" 75 | case .move(let from, let to): return "Move from \(from) to \(to)" 76 | } 77 | } 78 | } 79 | 80 | public typealias OutlineViewSnapshotDiff = [OutlineChangeInstruction] 81 | 82 | 83 | // Here is where the old snapshot and new snapshot are rectified 84 | extension OutlineViewSnapshotMember { 85 | // baseIndexPath is the index path of this item. 86 | // Its child indices get appended to it to make their own 87 | // index path. 88 | func instructions(forMorphingInto other: OutlineViewSnapshotMember, from baseIndexPath: IndexPath) -> OutlineViewSnapshotDiff { 89 | let src = children 90 | let dst = other.children 91 | 92 | var result = OutlineViewSnapshotDiff() 93 | 94 | func log(_ str: String) { 95 | // Uncomment for logging info 96 | // print(str) 97 | } 98 | 99 | var work = src 100 | if src != dst { 101 | 102 | log("\(baseIndexPath) BEGIN") 103 | log("\(src) -> \(dst)") 104 | log(" -> \(work)") 105 | 106 | func appendResult(_ inst: OutlineChangeInstruction) { 107 | result.append(inst) 108 | log("APPEND: \(inst)\n -> \(work)") 109 | } 110 | 111 | log("\(baseIndexPath) DELETE PHASE") 112 | // 1. Find things that don't belong and remove them. 113 | var deletables = [OutlineViewSnapshotMember]() 114 | for item in work { 115 | if !dst.contains(item) { 116 | deletables.append(item) 117 | } 118 | } 119 | for deletable in deletables { 120 | if let delIdx = work.firstIndex(of: deletable) { 121 | work.remove(at: delIdx) 122 | appendResult(.remove(deletable, baseIndexPath.appending(delIdx))) 123 | } 124 | } 125 | 126 | log("\(baseIndexPath) INSERT PHASE") 127 | // 2. Insert missing items. 128 | for (dstIdx, item) in dst.enumerated() { 129 | if work.firstIndex(of: item) == nil { 130 | // insert 131 | work.insert(item, at: dstIdx) 132 | appendResult(.insert(item, baseIndexPath.appending(dstIdx))) 133 | } 134 | } 135 | 136 | // 3. Moves 137 | // At this point src and dst have the same contents 138 | // possibly in different order 139 | 140 | log("\(baseIndexPath) MOVE PHASE") 141 | for (dstIdx, item) in dst.enumerated() { 142 | if let workIdx = work.firstIndex(of: item) { 143 | if workIdx != dstIdx { 144 | let dest = dstIdx > work.count ? work.count : dstIdx 145 | work.remove(at: workIdx) 146 | work.insert(item, at: dest) 147 | appendResult(.move(baseIndexPath.appending(workIdx), baseIndexPath.appending(dest))) 148 | } 149 | } 150 | } 151 | } 152 | 153 | log("\(baseIndexPath) RECURSION PHASE") 154 | 155 | // 4. Recurse 156 | // The hash value is based on the actual item, and not its children. 157 | // Ergo each item must generate its own instruction set. 158 | for (index, item) in dst.enumerated() { 159 | let indexPath = baseIndexPath.appending(index) 160 | if let workIdx = work.firstIndex(of: item) { 161 | let workItem = work[workIdx] 162 | result.append(contentsOf: workItem.instructions(forMorphingInto: item, from: indexPath)) 163 | } 164 | } 165 | 166 | return result 167 | } 168 | } 169 | -------------------------------------------------------------------------------- /Diffable Data Source/PassthroughWrappers.swift: -------------------------------------------------------------------------------- 1 | // 2 | // PassthroughWrappers.swift 3 | // OutlineViewDiffableDataSource 4 | // 5 | // Created by Steve Sparks on 3/1/20. 6 | // Copyright © 2020 Big Nerd Ranch. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import AppKit 11 | 12 | class SnapshotDataSourceWrapper: NSObject, NSOutlineViewDataSource { 13 | let dataSource: T 14 | unowned var snapshotDataSource: (NSObject & NSOutlineViewDataSource) 15 | 16 | init(_ wrapped: T, snapshot: (NSObject & NSOutlineViewDataSource)) { 17 | dataSource = wrapped 18 | snapshotDataSource = snapshot 19 | 20 | super.init() 21 | } 22 | 23 | enum OverriddenSelectors: String, CaseIterable { 24 | case outlineViewNumberOfChildrenOfItem = "outlineView:numberOfChildrenOfItem:" 25 | case outlineViewChildOfItem = "outlineView:child:ofItem:" 26 | case outlineViewIsItemExpandable = "outlineView:isItemExpandable:" 27 | } 28 | 29 | enum DataSourceSelectors: String, CaseIterable { 30 | case outlineViewPersistentObjectForItem = "outlineView:persistentObjectForItem:" 31 | case outlineViewItemForPersistentObject = "outlineView:itemForPersistentObject:" 32 | case outlineViewObjectValueForByItem = "outlineView:objectValueForTableColumn:byItem:" 33 | case outlineViewSetObjectValueForByItem = "outlineView:setObjectValue:forTableColumn:byItem:" 34 | case outlineViewSortDescriptorsDidChange = "outlineView:sortDescriptorsDidChange:" 35 | case outlineViewUpdateDraggingItemsForDrag = "outlineView:updateDraggingItemsForDrag:" 36 | case outlineViewPasteboardWriterForItem = "outlineView:pasteboardWriterForItem:" 37 | case outlineViewWriteItemsTo = "outlineView:writeItems:to:" 38 | case outlineViewValidateDrop = "outlineView:validateDrop:proposedItem:proposedChildIndex:" 39 | case outlineViewAcceptDrop = "outlineView:acceptDrop:item:childIndex:" 40 | case outlineViewDraggingBegin = "outlineView:draggingSession:willBeginAt:forItems:" 41 | case outlineViewDraggingEnd = "outlineView:draggingEndedAt:operation:" 42 | } 43 | 44 | override public class func instancesRespond(to aSelector: Selector!) -> Bool { 45 | let sel = aSelector.description 46 | var ret = false 47 | var ident = "???" 48 | 49 | if let _ = OverriddenSelectors(rawValue: sel) { 50 | ident = "OVR" 51 | ret = true 52 | } else if let _ = DataSourceSelectors(rawValue: sel) { 53 | ident = "DS " 54 | ret = T.instancesRespond(to: aSelector) 55 | } else { 56 | ret = super.responds(to: aSelector) 57 | } 58 | 59 | // change this to print() if you wish 60 | _ = "\(ident) \(sel) -> \(ret)" 61 | return ret 62 | } 63 | 64 | public func outlineView(_ outlineView: NSOutlineView, numberOfChildrenOfItem item: Any?) -> Int { 65 | return snapshotDataSource.outlineView!(outlineView, numberOfChildrenOfItem: item) 66 | } 67 | 68 | public func outlineView(_ outlineView: NSOutlineView, child index: Int, ofItem item: Any?) -> Any { 69 | return snapshotDataSource.outlineView!(outlineView, child: index, ofItem: item) 70 | } 71 | 72 | public func outlineView(_ outlineView: NSOutlineView, isItemExpandable item: Any) -> Bool { 73 | return snapshotDataSource.outlineView!(outlineView, isItemExpandable: item) 74 | } 75 | 76 | // MARK: - Data source pass through 77 | 78 | public func outlineView(_ outlineView: NSOutlineView, persistentObjectForItem item: Any?) -> Any? { 79 | return dataSource.outlineView!(outlineView, persistentObjectForItem: item) 80 | } 81 | 82 | public func outlineView(_ outlineView: NSOutlineView, itemForPersistentObject object: Any) -> Any? { 83 | return dataSource.outlineView!(outlineView, itemForPersistentObject: object) 84 | } 85 | 86 | public func outlineView(_ outlineView: NSOutlineView, objectValueFor tableColumn: NSTableColumn?, byItem item: Any?) -> Any? { 87 | return dataSource.outlineView!(outlineView, objectValueFor: tableColumn, byItem: item) 88 | } 89 | 90 | public func outlineView(_ outlineView: NSOutlineView, setObjectValue object: Any?, for tableColumn: NSTableColumn?, byItem item: Any?) { 91 | dataSource.outlineView!(outlineView, setObjectValue: object, for: tableColumn, byItem: item) 92 | } 93 | 94 | public func outlineView(_ outlineView: NSOutlineView, sortDescriptorsDidChange oldDescriptors: [NSSortDescriptor]) { 95 | dataSource.outlineView!(outlineView, sortDescriptorsDidChange: oldDescriptors) 96 | } 97 | 98 | public func outlineView(_ outlineView: NSOutlineView, updateDraggingItemsForDrag draggingInfo: NSDraggingInfo) { 99 | dataSource.outlineView!(outlineView, updateDraggingItemsForDrag: draggingInfo) 100 | } 101 | 102 | public func outlineView(_ outlineView: NSOutlineView, pasteboardWriterForItem item: Any) -> NSPasteboardWriting? { 103 | return dataSource.outlineView?(outlineView, pasteboardWriterForItem: item) 104 | } 105 | 106 | public func outlineView(_ outlineView: NSOutlineView, writeItems items: [Any], to pasteboard: NSPasteboard) -> Bool { 107 | return dataSource.outlineView!(outlineView, writeItems: items, to: pasteboard) 108 | } 109 | 110 | public func outlineView(_ outlineView: NSOutlineView, validateDrop info: NSDraggingInfo, proposedItem item: Any?, proposedChildIndex index: Int) -> NSDragOperation { 111 | return dataSource.outlineView?(outlineView, validateDrop: info, proposedItem: item, proposedChildIndex: index) ?? .generic 112 | } 113 | 114 | public func outlineView(_ outlineView: NSOutlineView, acceptDrop info: NSDraggingInfo, item: Any?, childIndex index: Int) -> Bool { 115 | return dataSource.outlineView?(outlineView, acceptDrop: info, item: item, childIndex: index) ?? false 116 | } 117 | 118 | public func outlineView(_ outlineView: NSOutlineView, draggingSession session: NSDraggingSession, willBeginAt screenPoint: NSPoint, forItems draggedItems: [Any]) { 119 | dataSource.outlineView?(outlineView, draggingSession: session, willBeginAt: screenPoint, forItems: draggedItems) 120 | } 121 | 122 | public func outlineView(_ outlineView: NSOutlineView, draggingSession session: NSDraggingSession, endedAt screenPoint: NSPoint, operation: NSDragOperation) { 123 | dataSource.outlineView?(outlineView, draggingSession: session, endedAt: screenPoint, operation: operation) 124 | } 125 | } 126 | 127 | class SnapshotDelegateWrapper: NSObject, NSOutlineViewDelegate { 128 | let delegate: T 129 | unowned var snapshotDelegate: (NSObject & NSOutlineViewDelegate) 130 | 131 | init(_ wrapped: T, snapshot: (NSObject & NSOutlineViewDelegate)) { 132 | delegate = wrapped 133 | snapshotDelegate = snapshot 134 | 135 | super.init() 136 | } 137 | 138 | enum DelegateSelectors: String, CaseIterable { 139 | case outlineViewColumnDidMove = "outlineViewColumnDidMove:" 140 | case outlineViewIsGroupItem = "outlineView:isGroupItem:" 141 | case outlineViewDidClick = "outlineView:didClick:" 142 | case outlineViewDidDrag = "outlineView:didDrag:" 143 | case outlineViewMouseDownInHeaderOf = "outlineView:mouseDownInHeaderOf:" 144 | case outlineViewShouldExpandItem = "outlineView:shouldExpandItem:" 145 | case outlineViewShouldCollapseItem = "outlineView:shouldCollapseItem:" 146 | case outlineViewShouldSelectItem = "outlineView:shouldSelectItem:" 147 | case outlineViewShouldSelectTableColumn = "outlineView:shouldSelect:" 148 | case outlineViewShouldEditTableColumn = "outlineView:shouldEdit:item:" 149 | case outlineViewViewForTableColumnItem = "outlineView:viewForTableColumn:item:" 150 | case outlineViewItemWillExpand = "outlineViewItemWillExpand:" 151 | case outlineViewItemWillCollapse = "outlineViewItemWillCollapse:" 152 | case outlineViewItemDidExpand = "outlineViewItemDidExpand:" 153 | case outlineViewItemDidCollapse = "outlineViewItemDidCollapse:" 154 | case outlineViewWillDisplayCellForTableColumnItem = "outlineView:willDisplayCell:forTableColumn:item:" 155 | case outlineViewWillDisplayOutlineCellForTableColumnItem = "outlineView:willDisplayOutlineCell:forTableColumn:item:" 156 | } 157 | 158 | override public class func instancesRespond(to aSelector: Selector!) -> Bool { 159 | let sel = aSelector.description 160 | var ret = false 161 | var ident = "???" 162 | 163 | if let _ = DelegateSelectors(rawValue: sel) { 164 | ident = "DS " 165 | ret = T.instancesRespond(to: aSelector) 166 | } 167 | 168 | // change this to print() if you wish 169 | _ = "\(ident) \(sel) -> \(ret)" 170 | return ret 171 | } 172 | 173 | // MARK: - NSOutlineViewDelegate 174 | 175 | public func outlineViewColumnDidMove(_ notification: Notification) { 176 | delegate.outlineViewColumnDidMove?(notification) 177 | } 178 | 179 | public func outlineView(_ outlineView: NSOutlineView, isGroupItem item: Any) -> Bool { 180 | return delegate.outlineView!(outlineView, isGroupItem: item) 181 | } 182 | 183 | public func outlineView(_ outlineView: NSOutlineView, didClick tableColumn: NSTableColumn) { 184 | delegate.outlineView!(outlineView, didClick: tableColumn) 185 | } 186 | 187 | public func outlineView(_ outlineView: NSOutlineView, didDrag tableColumn: NSTableColumn) { 188 | delegate.outlineView!(outlineView, didDrag: tableColumn) 189 | } 190 | 191 | public func outlineView(_ outlineView: NSOutlineView, mouseDownInHeaderOf tableColumn: NSTableColumn) { 192 | delegate.outlineView!(outlineView, mouseDownInHeaderOf: tableColumn) 193 | } 194 | 195 | public func outlineView(_ outlineView: NSOutlineView, shouldExpandItem item: Any) -> Bool { 196 | return delegate.outlineView!(outlineView, shouldExpandItem: item) 197 | } 198 | 199 | public func outlineView(_ outlineView: NSOutlineView, shouldSelectItem item: Any) -> Bool { 200 | return delegate.outlineView!(outlineView, shouldSelectItem: item) 201 | } 202 | 203 | public func outlineView(_ outlineView: NSOutlineView, shouldCollapseItem item: Any) -> Bool { 204 | return delegate.outlineView!(outlineView, shouldCollapseItem: item) 205 | } 206 | 207 | public func outlineView(_ outlineView: NSOutlineView, shouldSelect tableColumn: NSTableColumn?) -> Bool { 208 | return delegate.outlineView!(outlineView, shouldSelect: tableColumn) 209 | } 210 | 211 | public func outlineView(_ outlineView: NSOutlineView, shouldEdit tableColumn: NSTableColumn?, item: Any) -> Bool { 212 | return delegate.outlineView!(outlineView, shouldEdit: tableColumn, item: item) 213 | } 214 | 215 | public func outlineViewItemWillCollapse(_ notification: Notification) { 216 | delegate.outlineViewItemWillCollapse!(notification) 217 | } 218 | 219 | public func outlineViewItemWillExpand(_ notification: Notification) { 220 | delegate.outlineViewItemWillExpand!(notification) 221 | } 222 | 223 | public func outlineViewItemDidCollapse(_ notification: Notification) { 224 | delegate.outlineViewItemDidCollapse!(notification) 225 | } 226 | 227 | public func outlineViewItemDidExpand(_ notification: Notification) { 228 | delegate.outlineViewItemDidExpand!(notification) 229 | } 230 | public func outlineView(_ outlineView: NSOutlineView, viewFor tableColumn: NSTableColumn?, item: Any) -> NSView? { 231 | return delegate.outlineView!(outlineView, viewFor: tableColumn, item: item) ?? nil 232 | } 233 | // MARK: - To Do 234 | // TODO: Implement the loop: 235 | // - contrive a use of the method 236 | // - note the selector logged in `responds(to:)` 237 | // - add the selector to the DelegateSelectors array 238 | // - uncomment the method down below 239 | // - correct the code as necessary 240 | 241 | // public func outlineView(_ outlineView: NSOutlineView, shouldShowCellExpansionFor tableColumn: NSTableColumn?, item: Any) -> Bool { 242 | // report() 243 | // return delegate!.outlineView!(outlineView, shouldShowCellExpansionFor: tableColumn, item: item) ?? false 244 | // } 245 | // public func outlineView(_ outlineView: NSOutlineView, shouldReorderColumn columnIndex: Int, toColumn newColumnIndex: Int) -> Bool { 246 | // report() 247 | // return delegate!.outlineView!(outlineView, shouldReorderColumn: columnIndex, toColumn: newColumnIndex) ?? false 248 | // } 249 | // public func outlineView(_ outlineView: NSOutlineView, heightOfRowByItem item: Any) -> CGFloat { 250 | // report() 251 | // return delegate!.outlineView!(outlineView, heightOfRowByItem: item) ?? 252 | // delegate!.outlineView!(outlineView, viewFor: nil, item: item)?.fittingSize.height ?? 253 | // 16.0 254 | // } 255 | // public func outlineView(_ outlineView: NSOutlineView, sizeToFitWidthOfColumn column: Int) -> CGFloat { 256 | // report() 257 | // return delegate!.outlineView!(outlineView, sizeToFitWidthOfColumn: column) ?? 0.0 258 | // } 259 | // public func outlineView(_ outlineView: NSOutlineView, rowViewForItem item: Any) -> NSTableRowView? { 260 | // report() 261 | // return delegate!.outlineView!(outlineView, rowViewForItem: item) ?? nil 262 | // } 263 | // public func outlineView(_ outlineView: NSOutlineView, dataCellFor tableColumn: NSTableColumn?, item: Any) -> NSCell? { 264 | // report() 265 | // return delegate!.outlineView!(outlineView, dataCellFor: tableColumn, item: item) ?? nil 266 | // } 267 | // public func outlineView(_ outlineView: NSOutlineView, typeSelectStringFor tableColumn: NSTableColumn?, item: Any) -> String? { 268 | // report() 269 | // return delegate!.outlineView!(outlineView, typeSelectStringFor: tableColumn, item: item) ?? nil 270 | // } 271 | // public func outlineView(_ outlineView: NSOutlineView, shouldShowOutlineCellForItem item: Any) -> Bool { 272 | // report() 273 | // return delegate!.outlineView!(outlineView, shouldShowOutlineCellForItem: item) ?? false 274 | // } 275 | // 276 | // public func outlineView(_ outlineView: NSOutlineView, didAdd rowView: NSTableRowView, forRow row: Int) { 277 | // report() 278 | // } 279 | // public func outlineView(_ outlineView: NSOutlineView, didRemove rowView: NSTableRowView, forRow row: Int) { 280 | // report() 281 | // } 282 | // 283 | // public func outlineView(_ outlineView: NSOutlineView, willDisplayCell cell: Any, for tableColumn: NSTableColumn?, item: Any) { 284 | // report() 285 | // } 286 | // public func outlineView(_ outlineView: NSOutlineView, willDisplayOutlineCell cell: Any, for tableColumn: NSTableColumn?, item: Any) { 287 | // report() 288 | // } 289 | // public func outlineView(_ outlineView: NSOutlineView, shouldTrackCell cell: NSCell, for tableColumn: NSTableColumn?, item: Any) -> Bool { 290 | // report() 291 | // } 292 | // public func outlineView(_ outlineView: NSOutlineView, selectionIndexesForProposedSelection proposedSelectionIndexes: IndexSet) -> IndexSet { 293 | // report() 294 | // } 295 | // public func outlineView(_ outlineView: NSOutlineView, shouldTypeSelectFor event: NSEvent, withCurrentSearch searchString: String?) -> Bool { 296 | // report() 297 | // } 298 | // public func outlineView(_ outlineView: NSOutlineView, nextTypeSelectMatchFromItem startItem: Any, toItem endItem: Any, for searchString: String) -> Any? { 299 | // report() 300 | // } 301 | // public func outlineView(_ outlineView: NSOutlineView, toolTipFor cell: NSCell, rect: NSRectPointer, tableColumn: NSTableColumn?, item: Any, mouseLocation: NSPoint) -> String { 302 | // report() 303 | // } 304 | // public func selectionShouldChange(in outlineView: NSOutlineView) -> Bool { 305 | // report() 306 | // } 307 | } 308 | -------------------------------------------------------------------------------- /Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | $(CURRENT_PROJECT_VERSION) 21 | NSHumanReadableCopyright 22 | Copyright © 2020 Big Nerd Ranch. All rights reserved. 23 | 24 | 25 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Steve Sparks 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /OutlineTest/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // OutlineTest 4 | // 5 | // Created by Steve Sparks on 2/11/20. 6 | // Copyright © 2020 Big Nerd Ranch. All rights reserved. 7 | // 8 | 9 | import Cocoa 10 | 11 | @NSApplicationMain 12 | class AppDelegate: NSObject, NSApplicationDelegate { 13 | func applicationDidFinishLaunching(_ aNotification: Notification) { 14 | // Insert code here to initialize your application 15 | } 16 | 17 | func applicationWillTerminate(_ aNotification: Notification) { 18 | // Insert code here to tear down your application 19 | } 20 | 21 | 22 | } 23 | 24 | -------------------------------------------------------------------------------- /OutlineTest/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "mac", 5 | "size" : "16x16", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "mac", 10 | "size" : "16x16", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "mac", 15 | "size" : "32x32", 16 | "scale" : "1x" 17 | }, 18 | { 19 | "idiom" : "mac", 20 | "size" : "32x32", 21 | "scale" : "2x" 22 | }, 23 | { 24 | "idiom" : "mac", 25 | "size" : "128x128", 26 | "scale" : "1x" 27 | }, 28 | { 29 | "idiom" : "mac", 30 | "size" : "128x128", 31 | "scale" : "2x" 32 | }, 33 | { 34 | "idiom" : "mac", 35 | "size" : "256x256", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "mac", 40 | "size" : "256x256", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "mac", 45 | "size" : "512x512", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "mac", 50 | "size" : "512x512", 51 | "scale" : "2x" 52 | } 53 | ], 54 | "info" : { 55 | "version" : 1, 56 | "author" : "xcode" 57 | } 58 | } -------------------------------------------------------------------------------- /OutlineTest/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /OutlineTest/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 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 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 | 454 | 455 | 456 | 457 | 458 | 459 | 460 | 461 | 462 | 463 | 464 | 465 | 466 | 467 | 468 | 469 | 470 | 471 | 472 | 473 | 474 | 475 | 476 | 477 | 478 | 479 | 480 | 481 | 482 | 483 | 484 | 485 | 486 | 487 | 488 | 489 | 490 | 491 | 492 | 493 | 494 | 495 | 496 | 497 | 498 | 499 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 509 | 510 | 511 | 512 | 513 | 514 | 515 | 516 | 517 | 518 | 519 | 520 | 521 | 522 | 523 | 524 | 525 | 526 | 527 | 528 | 529 | Default 530 | 531 | 532 | 533 | 534 | 535 | 536 | Left to Right 537 | 538 | 539 | 540 | 541 | 542 | 543 | Right to Left 544 | 545 | 546 | 547 | 548 | 549 | 550 | 551 | 552 | 553 | 554 | Default 555 | 556 | 557 | 558 | 559 | 560 | 561 | Left to Right 562 | 563 | 564 | 565 | 566 | 567 | 568 | Right to Left 569 | 570 | 571 | 572 | 573 | 574 | 575 | 576 | 577 | 578 | 579 | 580 | 581 | 582 | 583 | 584 | 585 | 586 | 587 | 588 | 589 | 590 | 591 | 592 | 593 | 594 | 595 | 596 | 597 | 598 | 599 | 600 | 601 | 602 | 603 | 604 | 605 | 606 | 607 | 608 | 609 | 610 | 611 | 612 | 613 | 614 | 615 | 616 | 617 | 618 | 619 | 620 | 621 | 622 | 623 | 624 | 625 | 626 | 627 | 628 | 629 | 630 | 631 | 632 | 633 | 634 | 635 | 636 | 637 | 638 | 639 | 640 | 641 | 642 | 643 | 644 | 645 | 646 | 647 | 648 | 649 | 650 | 651 | 652 | 653 | 654 | 655 | 656 | 657 | 658 | 659 | 660 | 661 | 662 | 663 | 664 | 665 | 666 | 667 | 668 | 669 | 670 | 671 | 672 | 673 | 674 | 675 | 676 | 677 | 678 | 679 | 680 | 681 | 682 | 683 | 684 | 685 | 686 | 687 | 688 | 689 | 690 | 691 | 692 | 693 | 694 | 695 | 696 | 697 | 698 | 699 | 700 | 701 | 702 | 703 | 704 | 705 | 706 | 707 | 708 | 709 | 710 | 711 | 712 | 713 | 714 | 715 | 716 | 717 | 718 | 719 | 720 | 721 | 722 | 723 | 724 | 725 | 726 | 727 | 728 | 729 | 730 | 731 | 732 | 733 | 734 | 735 | 736 | 737 | 738 | 739 | 740 | 741 | 742 | 746 | 750 | 751 | 752 | 753 | 754 | 755 | 765 | 766 | 767 | 768 | 769 | 770 | 771 | 772 | 773 | 774 | 775 | 776 | 777 | 778 | 779 | 780 | 781 | 782 | 783 | 784 | 785 | -------------------------------------------------------------------------------- /OutlineTest/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIconFile 10 | 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | $(PRODUCT_NAME) 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleVersion 22 | 1 23 | LSMinimumSystemVersion 24 | $(MACOSX_DEPLOYMENT_TARGET) 25 | NSHumanReadableCopyright 26 | Copyright © 2020 Big Nerd Ranch. All rights reserved. 27 | NSMainStoryboardFile 28 | Main 29 | NSPrincipalClass 30 | NSApplication 31 | 32 | 33 | -------------------------------------------------------------------------------- /OutlineTest/OutlineTest.entitlements: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | com.apple.security.app-sandbox 6 | 7 | com.apple.security.files.user-selected.read-only 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /OutlineTest/ReorderableArrayDataSource.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ReorderableArrayDataSource.swift 3 | // OutlineTest 4 | // 5 | // Created by Steve Sparks on 2/11/20. 6 | // Copyright © 2020 Big Nerd Ranch. All rights reserved. 7 | // 8 | 9 | import Cocoa 10 | 11 | class ReorderableArrayDataSource: ArrayDataSource { 12 | var draggedItem: String? 13 | 14 | var replacementDest: AnyHashable? 15 | var replacementIndex: Int? 16 | 17 | // Set the string 18 | func outlineView(_ outlineView: NSOutlineView, pasteboardWriterForItem item: Any) -> NSPasteboardWriting? { 19 | let pasteboardItem = NSPasteboardItem() 20 | pasteboardItem.setString(String(describing: item), forType: NSPasteboard.PasteboardType.string) 21 | return pasteboardItem 22 | } 23 | 24 | // Decide if it's okay to land here 25 | func outlineView(_ outlineView: NSOutlineView, validateDrop info: NSDraggingInfo, proposedItem item: Any?, proposedChildIndex index: Int) -> NSDragOperation { 26 | if let item = item as? String, 27 | let sourceText = info.draggingPasteboard.string(forType: .string), 28 | item != sourceText { 29 | return .move 30 | } 31 | if item == nil { return .move } 32 | return [] 33 | } 34 | 35 | func outlineView(_ outlineView: NSOutlineView, acceptDrop info: NSDraggingInfo, item: Any?, childIndex index: Int) -> Bool { 36 | guard let sourceText = info.draggingPasteboard.string(forType: .string) else { return false } 37 | if let item = item as? String { 38 | if item == sourceText { return false } 39 | let targetDescription: String = { 40 | return index == -1 ? "onto \(item)" : "into index \(index) of \(item)" 41 | }() 42 | report("drop `\(sourceText)` \(targetDescription)") 43 | if var arr = contents[item] { 44 | if index >= 0, index <= arr.count { 45 | arr.insert(sourceText, at: index) 46 | } else { 47 | arr.append(sourceText) 48 | } 49 | contents[item] = arr 50 | } else { 51 | contents[item] = [sourceText] 52 | } 53 | return true 54 | } else if item == nil { 55 | print("Dropped into window but not on a row") 56 | contents[ArrayDataSource.RootIdentfier]?.append(sourceText) 57 | return true 58 | } else { 59 | return false 60 | } 61 | } 62 | 63 | func outlineView(_ outlineView: NSOutlineView, draggingSession session: NSDraggingSession, willBeginAt screenPoint: NSPoint, forItems draggedItems: [Any]) { 64 | if let item = draggedItems.first as? String { 65 | draggedItem = item 66 | if let (dest, idx) = self.remove(item) { 67 | replacementDest = dest 68 | replacementIndex = idx 69 | } 70 | } 71 | 72 | report(" \(draggedItems.map({ return String.init(describing: $0) }).joined(separator: " "))") 73 | } 74 | 75 | public func outlineView(_ outlineView: NSOutlineView, draggingSession session: NSDraggingSession, endedAt screenPoint: NSPoint, operation: NSDragOperation) { 76 | guard let sourceText = session.draggingPasteboard.string(forType: .string) else { return } 77 | guard operation == .move else { 78 | if let dest = replacementDest, let idx = replacementIndex { 79 | var arr = contents[dest]! 80 | arr.insert(sourceText, at: idx) 81 | contents[dest] = arr 82 | } 83 | return 84 | } 85 | report("\(operation) \(sourceText)") 86 | } 87 | 88 | func report(_ message: String = "", _ preamble: String = "", function: String = #function) { 89 | let fn = String(describing: type(of: self)) 90 | print("--> \(preamble)\(fn) \(function) \(message) ") 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /OutlineTest/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // OutlineTest 4 | // 5 | // Created by Steve Sparks on 2/11/20. 6 | // Copyright © 2020 Big Nerd Ranch. All rights reserved. 7 | // 8 | 9 | import Cocoa 10 | import OutlineViewDiffableDataSource 11 | 12 | var acceptableTypes = [NSPasteboard.PasteboardType.string] 13 | 14 | class ViewController: NSViewController { 15 | @IBOutlet weak var outlineView: NSOutlineView! 16 | 17 | let ds = ReorderableArrayDataSource() 18 | 19 | var diff: OutlineViewDiffableDataSource! 20 | 21 | override func viewDidLoad() { 22 | super.viewDidLoad() 23 | 24 | outlineView.registerForDraggedTypes(Array(acceptableTypes)) 25 | ds.contents = [ 26 | ArrayDataSource.RootIdentfier: ["A", "B"], 27 | "A": ["A1", "A2"], 28 | "A1": ["A1a", "A1b"], 29 | "B": ["B1", "B2"], 30 | "B2": ["B2b"] 31 | ] 32 | 33 | diff = OutlineViewDiffableDataSource(baseDataSource: ds, targetView: outlineView, delegate: ds) 34 | 35 | outlineView.dataSource = diff 36 | outlineView.delegate = diff 37 | 38 | diff.applySnapshot() 39 | // Do any additional setup after loading the view. 40 | } 41 | 42 | override func viewDidAppear() { 43 | super.viewDidAppear() 44 | 45 | outlineView.expandItem(nil, expandChildren: true) 46 | } 47 | 48 | override var representedObject: Any? { 49 | didSet { 50 | // Update the view, if already loaded. 51 | } 52 | } 53 | 54 | @objc 55 | @IBAction func moveStuff(_ sender: Any?) { 56 | ds.contents["A"] = ["A2"] 57 | ds.contents["A1"] = ["A1b", "A1a", "A1c"] 58 | ds.contents["B"] = ["B2", "B1", "A1"] 59 | diff.applySnapshot() 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /OutlineTestTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /OutlineTestTests/OutlineTestTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // OutlineTestTests.swift 3 | // OutlineTestTests 4 | // 5 | // Created by Steve Sparks on 2/11/20. 6 | // Copyright © 2020 Big Nerd Ranch. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | @testable import OutlineTest 11 | 12 | class OutlineTestTests: XCTestCase { 13 | 14 | override func setUp() { 15 | // Put setup code here. This method is called before the invocation of each test method in the class. 16 | } 17 | 18 | override func tearDown() { 19 | // Put teardown code here. This method is called after the invocation of each test method in the class. 20 | } 21 | 22 | func testExample() { 23 | // This is an example of a functional test case. 24 | // Use XCTAssert and related functions to verify your tests produce the correct results. 25 | } 26 | 27 | func testPerformanceExample() { 28 | // This is an example of a performance test case. 29 | self.measure { 30 | // Put the code you want to measure the time of here. 31 | } 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /OutlineViewDiffableDataSource.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 50; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 0E0BABD423F0208A00A3428F /* OutlineViewDataSource+Passthrough.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E0BABD323F0208A00A3428F /* OutlineViewDataSource+Passthrough.swift */; }; 11 | 0E0BABD623F19AFF00A3428F /* OutlineViewSnapshotTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E0BABD523F19AFF00A3428F /* OutlineViewSnapshotTests.swift */; }; 12 | 0E0BABD823F19B5D00A3428F /* ArrayDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E0BABD723F19B5D00A3428F /* ArrayDataSource.swift */; }; 13 | 0E36A29523F34AE70002445A /* ReorderableArrayDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E36A29423F34AE70002445A /* ReorderableArrayDataSource.swift */; }; 14 | 0E6344AB23F2B3D900870976 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E6344AA23F2B3D900870976 /* AppDelegate.swift */; }; 15 | 0E6344AD23F2B3D900870976 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E6344AC23F2B3D900870976 /* ViewController.swift */; }; 16 | 0E6344AF23F2B3DC00870976 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 0E6344AE23F2B3DC00870976 /* Assets.xcassets */; }; 17 | 0E6344B223F2B3DC00870976 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 0E6344B023F2B3DC00870976 /* Main.storyboard */; }; 18 | 0E6344BE23F2B3DC00870976 /* OutlineTestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E6344BD23F2B3DC00870976 /* OutlineTestTests.swift */; }; 19 | 0E6344C623F2B49D00870976 /* ArrayDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E0BABD723F19B5D00A3428F /* ArrayDataSource.swift */; }; 20 | 0E6344C823F2B4C200870976 /* OutlineViewDiffableDataSource.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0E76A68A23EEE5CD007321F1 /* OutlineViewDiffableDataSource.framework */; }; 21 | 0E69D6A0240BE18200873FF2 /* PassthroughWrappers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E69D69F240BE18200873FF2 /* PassthroughWrappers.swift */; }; 22 | 0E76A69423EEE5CD007321F1 /* OutlineViewDiffableDataSource.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0E76A68A23EEE5CD007321F1 /* OutlineViewDiffableDataSource.framework */; }; 23 | 0E76A69923EEE5CD007321F1 /* OutlineViewDiffableDataSourceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E76A69823EEE5CD007321F1 /* OutlineViewDiffableDataSourceTests.swift */; }; 24 | 0E76A69B23EEE5CD007321F1 /* OutlineViewDiffableDataSource.h in Headers */ = {isa = PBXBuildFile; fileRef = 0E76A68D23EEE5CD007321F1 /* OutlineViewDiffableDataSource.h */; settings = {ATTRIBUTES = (Public, ); }; }; 25 | 0E76A6A523EEE5F2007321F1 /* OutlineViewDiffableDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E76A6A423EEE5F2007321F1 /* OutlineViewDiffableDataSource.swift */; }; 26 | 0E76A6A723EEE632007321F1 /* OutlineViewSnapshotMember.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E76A6A623EEE632007321F1 /* OutlineViewSnapshotMember.swift */; }; 27 | 0E76A6A923EEE649007321F1 /* NSOutlineView+Snapshot.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E76A6A823EEE649007321F1 /* NSOutlineView+Snapshot.swift */; }; 28 | 0E76A6AB23EEE7E6007321F1 /* OutlineViewSnapshot.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E76A6AA23EEE7E6007321F1 /* OutlineViewSnapshot.swift */; }; 29 | /* End PBXBuildFile section */ 30 | 31 | /* Begin PBXContainerItemProxy section */ 32 | 0E6344BA23F2B3DC00870976 /* PBXContainerItemProxy */ = { 33 | isa = PBXContainerItemProxy; 34 | containerPortal = 0E76A68123EEE5CD007321F1 /* Project object */; 35 | proxyType = 1; 36 | remoteGlobalIDString = 0E6344A723F2B3D900870976; 37 | remoteInfo = OutlineTest; 38 | }; 39 | 0E76A69523EEE5CD007321F1 /* PBXContainerItemProxy */ = { 40 | isa = PBXContainerItemProxy; 41 | containerPortal = 0E76A68123EEE5CD007321F1 /* Project object */; 42 | proxyType = 1; 43 | remoteGlobalIDString = 0E76A68923EEE5CD007321F1; 44 | remoteInfo = OutlineViewDiffableDataSource; 45 | }; 46 | /* End PBXContainerItemProxy section */ 47 | 48 | /* Begin PBXFileReference section */ 49 | 0E0BABD323F0208A00A3428F /* OutlineViewDataSource+Passthrough.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "OutlineViewDataSource+Passthrough.swift"; sourceTree = ""; }; 50 | 0E0BABD523F19AFF00A3428F /* OutlineViewSnapshotTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OutlineViewSnapshotTests.swift; sourceTree = ""; }; 51 | 0E0BABD723F19B5D00A3428F /* ArrayDataSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArrayDataSource.swift; sourceTree = ""; }; 52 | 0E36A29423F34AE70002445A /* ReorderableArrayDataSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReorderableArrayDataSource.swift; sourceTree = ""; }; 53 | 0E6344A823F2B3D900870976 /* OutlineTest.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = OutlineTest.app; sourceTree = BUILT_PRODUCTS_DIR; }; 54 | 0E6344AA23F2B3D900870976 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 55 | 0E6344AC23F2B3D900870976 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 56 | 0E6344AE23F2B3DC00870976 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 57 | 0E6344B123F2B3DC00870976 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 58 | 0E6344B323F2B3DC00870976 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 59 | 0E6344B423F2B3DC00870976 /* OutlineTest.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = OutlineTest.entitlements; sourceTree = ""; }; 60 | 0E6344B923F2B3DC00870976 /* OutlineTestTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = OutlineTestTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 61 | 0E6344BD23F2B3DC00870976 /* OutlineTestTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OutlineTestTests.swift; sourceTree = ""; }; 62 | 0E6344BF23F2B3DC00870976 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 63 | 0E69D69F240BE18200873FF2 /* PassthroughWrappers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PassthroughWrappers.swift; sourceTree = ""; }; 64 | 0E76A68A23EEE5CD007321F1 /* OutlineViewDiffableDataSource.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = OutlineViewDiffableDataSource.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 65 | 0E76A68D23EEE5CD007321F1 /* OutlineViewDiffableDataSource.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OutlineViewDiffableDataSource.h; sourceTree = ""; }; 66 | 0E76A68E23EEE5CD007321F1 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 67 | 0E76A69323EEE5CD007321F1 /* OutlineViewDiffableDataSourceTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = OutlineViewDiffableDataSourceTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 68 | 0E76A69823EEE5CD007321F1 /* OutlineViewDiffableDataSourceTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OutlineViewDiffableDataSourceTests.swift; sourceTree = ""; }; 69 | 0E76A69A23EEE5CD007321F1 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 70 | 0E76A6A423EEE5F2007321F1 /* OutlineViewDiffableDataSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OutlineViewDiffableDataSource.swift; sourceTree = ""; }; 71 | 0E76A6A623EEE632007321F1 /* OutlineViewSnapshotMember.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OutlineViewSnapshotMember.swift; sourceTree = ""; }; 72 | 0E76A6A823EEE649007321F1 /* NSOutlineView+Snapshot.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSOutlineView+Snapshot.swift"; sourceTree = ""; }; 73 | 0E76A6AA23EEE7E6007321F1 /* OutlineViewSnapshot.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OutlineViewSnapshot.swift; sourceTree = ""; }; 74 | /* End PBXFileReference section */ 75 | 76 | /* Begin PBXFrameworksBuildPhase section */ 77 | 0E6344A523F2B3D900870976 /* Frameworks */ = { 78 | isa = PBXFrameworksBuildPhase; 79 | buildActionMask = 2147483647; 80 | files = ( 81 | 0E6344C823F2B4C200870976 /* OutlineViewDiffableDataSource.framework in Frameworks */, 82 | ); 83 | runOnlyForDeploymentPostprocessing = 0; 84 | }; 85 | 0E6344B623F2B3DC00870976 /* Frameworks */ = { 86 | isa = PBXFrameworksBuildPhase; 87 | buildActionMask = 2147483647; 88 | files = ( 89 | ); 90 | runOnlyForDeploymentPostprocessing = 0; 91 | }; 92 | 0E76A68723EEE5CD007321F1 /* Frameworks */ = { 93 | isa = PBXFrameworksBuildPhase; 94 | buildActionMask = 2147483647; 95 | files = ( 96 | ); 97 | runOnlyForDeploymentPostprocessing = 0; 98 | }; 99 | 0E76A69023EEE5CD007321F1 /* Frameworks */ = { 100 | isa = PBXFrameworksBuildPhase; 101 | buildActionMask = 2147483647; 102 | files = ( 103 | 0E76A69423EEE5CD007321F1 /* OutlineViewDiffableDataSource.framework in Frameworks */, 104 | ); 105 | runOnlyForDeploymentPostprocessing = 0; 106 | }; 107 | /* End PBXFrameworksBuildPhase section */ 108 | 109 | /* Begin PBXGroup section */ 110 | 0E6344A923F2B3D900870976 /* OutlineTest */ = { 111 | isa = PBXGroup; 112 | children = ( 113 | 0E6344AA23F2B3D900870976 /* AppDelegate.swift */, 114 | 0E6344AC23F2B3D900870976 /* ViewController.swift */, 115 | 0E36A29423F34AE70002445A /* ReorderableArrayDataSource.swift */, 116 | 0E6344AE23F2B3DC00870976 /* Assets.xcassets */, 117 | 0E6344B023F2B3DC00870976 /* Main.storyboard */, 118 | 0E6344B323F2B3DC00870976 /* Info.plist */, 119 | 0E6344B423F2B3DC00870976 /* OutlineTest.entitlements */, 120 | ); 121 | path = OutlineTest; 122 | sourceTree = ""; 123 | }; 124 | 0E6344BC23F2B3DC00870976 /* OutlineTestTests */ = { 125 | isa = PBXGroup; 126 | children = ( 127 | 0E6344BD23F2B3DC00870976 /* OutlineTestTests.swift */, 128 | 0E6344BF23F2B3DC00870976 /* Info.plist */, 129 | ); 130 | path = OutlineTestTests; 131 | sourceTree = ""; 132 | }; 133 | 0E6344C723F2B4C200870976 /* Frameworks */ = { 134 | isa = PBXGroup; 135 | children = ( 136 | ); 137 | name = Frameworks; 138 | sourceTree = ""; 139 | }; 140 | 0E76A68023EEE5CD007321F1 = { 141 | isa = PBXGroup; 142 | children = ( 143 | 0E76A68E23EEE5CD007321F1 /* Info.plist */, 144 | 0E76A68C23EEE5CD007321F1 /* OutlineViewDiffableDataSource */, 145 | 0E76A69723EEE5CD007321F1 /* OutlineViewDiffableDataSourceTests */, 146 | 0E6344A923F2B3D900870976 /* OutlineTest */, 147 | 0E6344BC23F2B3DC00870976 /* OutlineTestTests */, 148 | 0E76A68B23EEE5CD007321F1 /* Products */, 149 | 0E6344C723F2B4C200870976 /* Frameworks */, 150 | ); 151 | sourceTree = ""; 152 | }; 153 | 0E76A68B23EEE5CD007321F1 /* Products */ = { 154 | isa = PBXGroup; 155 | children = ( 156 | 0E76A68A23EEE5CD007321F1 /* OutlineViewDiffableDataSource.framework */, 157 | 0E76A69323EEE5CD007321F1 /* OutlineViewDiffableDataSourceTests.xctest */, 158 | 0E6344A823F2B3D900870976 /* OutlineTest.app */, 159 | 0E6344B923F2B3DC00870976 /* OutlineTestTests.xctest */, 160 | ); 161 | name = Products; 162 | sourceTree = ""; 163 | }; 164 | 0E76A68C23EEE5CD007321F1 /* OutlineViewDiffableDataSource */ = { 165 | isa = PBXGroup; 166 | children = ( 167 | 0ECB2C0023F31904008103EE /* Diffable Data Source */, 168 | ); 169 | name = OutlineViewDiffableDataSource; 170 | sourceTree = ""; 171 | }; 172 | 0E76A69723EEE5CD007321F1 /* OutlineViewDiffableDataSourceTests */ = { 173 | isa = PBXGroup; 174 | children = ( 175 | 0E76A69823EEE5CD007321F1 /* OutlineViewDiffableDataSourceTests.swift */, 176 | 0E76A69A23EEE5CD007321F1 /* Info.plist */, 177 | 0E0BABD523F19AFF00A3428F /* OutlineViewSnapshotTests.swift */, 178 | 0E0BABD723F19B5D00A3428F /* ArrayDataSource.swift */, 179 | ); 180 | path = OutlineViewDiffableDataSourceTests; 181 | sourceTree = ""; 182 | }; 183 | 0ECB2C0023F31904008103EE /* Diffable Data Source */ = { 184 | isa = PBXGroup; 185 | children = ( 186 | 0E76A68D23EEE5CD007321F1 /* OutlineViewDiffableDataSource.h */, 187 | 0E76A6A423EEE5F2007321F1 /* OutlineViewDiffableDataSource.swift */, 188 | 0E76A6A623EEE632007321F1 /* OutlineViewSnapshotMember.swift */, 189 | 0E76A6A823EEE649007321F1 /* NSOutlineView+Snapshot.swift */, 190 | 0E76A6AA23EEE7E6007321F1 /* OutlineViewSnapshot.swift */, 191 | 0E0BABD323F0208A00A3428F /* OutlineViewDataSource+Passthrough.swift */, 192 | 0E69D69F240BE18200873FF2 /* PassthroughWrappers.swift */, 193 | ); 194 | path = "Diffable Data Source"; 195 | sourceTree = ""; 196 | }; 197 | /* End PBXGroup section */ 198 | 199 | /* Begin PBXHeadersBuildPhase section */ 200 | 0E76A68523EEE5CD007321F1 /* Headers */ = { 201 | isa = PBXHeadersBuildPhase; 202 | buildActionMask = 2147483647; 203 | files = ( 204 | 0E76A69B23EEE5CD007321F1 /* OutlineViewDiffableDataSource.h in Headers */, 205 | ); 206 | runOnlyForDeploymentPostprocessing = 0; 207 | }; 208 | /* End PBXHeadersBuildPhase section */ 209 | 210 | /* Begin PBXNativeTarget section */ 211 | 0E6344A723F2B3D900870976 /* OutlineTest */ = { 212 | isa = PBXNativeTarget; 213 | buildConfigurationList = 0E6344C423F2B3DC00870976 /* Build configuration list for PBXNativeTarget "OutlineTest" */; 214 | buildPhases = ( 215 | 0E6344A423F2B3D900870976 /* Sources */, 216 | 0E6344A523F2B3D900870976 /* Frameworks */, 217 | 0E6344A623F2B3D900870976 /* Resources */, 218 | ); 219 | buildRules = ( 220 | ); 221 | dependencies = ( 222 | ); 223 | name = OutlineTest; 224 | productName = OutlineTest; 225 | productReference = 0E6344A823F2B3D900870976 /* OutlineTest.app */; 226 | productType = "com.apple.product-type.application"; 227 | }; 228 | 0E6344B823F2B3DC00870976 /* OutlineTestTests */ = { 229 | isa = PBXNativeTarget; 230 | buildConfigurationList = 0E6344C523F2B3DC00870976 /* Build configuration list for PBXNativeTarget "OutlineTestTests" */; 231 | buildPhases = ( 232 | 0E6344B523F2B3DC00870976 /* Sources */, 233 | 0E6344B623F2B3DC00870976 /* Frameworks */, 234 | 0E6344B723F2B3DC00870976 /* Resources */, 235 | ); 236 | buildRules = ( 237 | ); 238 | dependencies = ( 239 | 0E6344BB23F2B3DC00870976 /* PBXTargetDependency */, 240 | ); 241 | name = OutlineTestTests; 242 | productName = OutlineTestTests; 243 | productReference = 0E6344B923F2B3DC00870976 /* OutlineTestTests.xctest */; 244 | productType = "com.apple.product-type.bundle.unit-test"; 245 | }; 246 | 0E76A68923EEE5CD007321F1 /* OutlineViewDiffableDataSource */ = { 247 | isa = PBXNativeTarget; 248 | buildConfigurationList = 0E76A69E23EEE5CD007321F1 /* Build configuration list for PBXNativeTarget "OutlineViewDiffableDataSource" */; 249 | buildPhases = ( 250 | 0E76A68523EEE5CD007321F1 /* Headers */, 251 | 0E76A68623EEE5CD007321F1 /* Sources */, 252 | 0E76A68723EEE5CD007321F1 /* Frameworks */, 253 | 0E76A68823EEE5CD007321F1 /* Resources */, 254 | ); 255 | buildRules = ( 256 | ); 257 | dependencies = ( 258 | ); 259 | name = OutlineViewDiffableDataSource; 260 | productName = OutlineViewDiffableDataSource; 261 | productReference = 0E76A68A23EEE5CD007321F1 /* OutlineViewDiffableDataSource.framework */; 262 | productType = "com.apple.product-type.framework"; 263 | }; 264 | 0E76A69223EEE5CD007321F1 /* OutlineViewDiffableDataSourceTests */ = { 265 | isa = PBXNativeTarget; 266 | buildConfigurationList = 0E76A6A123EEE5CD007321F1 /* Build configuration list for PBXNativeTarget "OutlineViewDiffableDataSourceTests" */; 267 | buildPhases = ( 268 | 0E76A68F23EEE5CD007321F1 /* Sources */, 269 | 0E76A69023EEE5CD007321F1 /* Frameworks */, 270 | 0E76A69123EEE5CD007321F1 /* Resources */, 271 | ); 272 | buildRules = ( 273 | ); 274 | dependencies = ( 275 | 0E76A69623EEE5CD007321F1 /* PBXTargetDependency */, 276 | ); 277 | name = OutlineViewDiffableDataSourceTests; 278 | productName = OutlineViewDiffableDataSourceTests; 279 | productReference = 0E76A69323EEE5CD007321F1 /* OutlineViewDiffableDataSourceTests.xctest */; 280 | productType = "com.apple.product-type.bundle.unit-test"; 281 | }; 282 | /* End PBXNativeTarget section */ 283 | 284 | /* Begin PBXProject section */ 285 | 0E76A68123EEE5CD007321F1 /* Project object */ = { 286 | isa = PBXProject; 287 | attributes = { 288 | LastSwiftUpdateCheck = 1020; 289 | LastUpgradeCheck = 1020; 290 | ORGANIZATIONNAME = "Big Nerd Ranch"; 291 | TargetAttributes = { 292 | 0E6344A723F2B3D900870976 = { 293 | CreatedOnToolsVersion = 10.2.1; 294 | }; 295 | 0E6344B823F2B3DC00870976 = { 296 | CreatedOnToolsVersion = 10.2.1; 297 | TestTargetID = 0E6344A723F2B3D900870976; 298 | }; 299 | 0E76A68923EEE5CD007321F1 = { 300 | CreatedOnToolsVersion = 10.2.1; 301 | LastSwiftMigration = 1020; 302 | }; 303 | 0E76A69223EEE5CD007321F1 = { 304 | CreatedOnToolsVersion = 10.2.1; 305 | }; 306 | }; 307 | }; 308 | buildConfigurationList = 0E76A68423EEE5CD007321F1 /* Build configuration list for PBXProject "OutlineViewDiffableDataSource" */; 309 | compatibilityVersion = "Xcode 9.3"; 310 | developmentRegion = en; 311 | hasScannedForEncodings = 0; 312 | knownRegions = ( 313 | en, 314 | Base, 315 | ); 316 | mainGroup = 0E76A68023EEE5CD007321F1; 317 | productRefGroup = 0E76A68B23EEE5CD007321F1 /* Products */; 318 | projectDirPath = ""; 319 | projectRoot = ""; 320 | targets = ( 321 | 0E76A68923EEE5CD007321F1 /* OutlineViewDiffableDataSource */, 322 | 0E76A69223EEE5CD007321F1 /* OutlineViewDiffableDataSourceTests */, 323 | 0E6344A723F2B3D900870976 /* OutlineTest */, 324 | 0E6344B823F2B3DC00870976 /* OutlineTestTests */, 325 | ); 326 | }; 327 | /* End PBXProject section */ 328 | 329 | /* Begin PBXResourcesBuildPhase section */ 330 | 0E6344A623F2B3D900870976 /* Resources */ = { 331 | isa = PBXResourcesBuildPhase; 332 | buildActionMask = 2147483647; 333 | files = ( 334 | 0E6344AF23F2B3DC00870976 /* Assets.xcassets in Resources */, 335 | 0E6344B223F2B3DC00870976 /* Main.storyboard in Resources */, 336 | ); 337 | runOnlyForDeploymentPostprocessing = 0; 338 | }; 339 | 0E6344B723F2B3DC00870976 /* Resources */ = { 340 | isa = PBXResourcesBuildPhase; 341 | buildActionMask = 2147483647; 342 | files = ( 343 | ); 344 | runOnlyForDeploymentPostprocessing = 0; 345 | }; 346 | 0E76A68823EEE5CD007321F1 /* Resources */ = { 347 | isa = PBXResourcesBuildPhase; 348 | buildActionMask = 2147483647; 349 | files = ( 350 | ); 351 | runOnlyForDeploymentPostprocessing = 0; 352 | }; 353 | 0E76A69123EEE5CD007321F1 /* Resources */ = { 354 | isa = PBXResourcesBuildPhase; 355 | buildActionMask = 2147483647; 356 | files = ( 357 | ); 358 | runOnlyForDeploymentPostprocessing = 0; 359 | }; 360 | /* End PBXResourcesBuildPhase section */ 361 | 362 | /* Begin PBXSourcesBuildPhase section */ 363 | 0E6344A423F2B3D900870976 /* Sources */ = { 364 | isa = PBXSourcesBuildPhase; 365 | buildActionMask = 2147483647; 366 | files = ( 367 | 0E36A29523F34AE70002445A /* ReorderableArrayDataSource.swift in Sources */, 368 | 0E6344AD23F2B3D900870976 /* ViewController.swift in Sources */, 369 | 0E6344C623F2B49D00870976 /* ArrayDataSource.swift in Sources */, 370 | 0E6344AB23F2B3D900870976 /* AppDelegate.swift in Sources */, 371 | ); 372 | runOnlyForDeploymentPostprocessing = 0; 373 | }; 374 | 0E6344B523F2B3DC00870976 /* Sources */ = { 375 | isa = PBXSourcesBuildPhase; 376 | buildActionMask = 2147483647; 377 | files = ( 378 | 0E6344BE23F2B3DC00870976 /* OutlineTestTests.swift in Sources */, 379 | ); 380 | runOnlyForDeploymentPostprocessing = 0; 381 | }; 382 | 0E76A68623EEE5CD007321F1 /* Sources */ = { 383 | isa = PBXSourcesBuildPhase; 384 | buildActionMask = 2147483647; 385 | files = ( 386 | 0E69D6A0240BE18200873FF2 /* PassthroughWrappers.swift in Sources */, 387 | 0E76A6A523EEE5F2007321F1 /* OutlineViewDiffableDataSource.swift in Sources */, 388 | 0E76A6AB23EEE7E6007321F1 /* OutlineViewSnapshot.swift in Sources */, 389 | 0E0BABD423F0208A00A3428F /* OutlineViewDataSource+Passthrough.swift in Sources */, 390 | 0E76A6A923EEE649007321F1 /* NSOutlineView+Snapshot.swift in Sources */, 391 | 0E76A6A723EEE632007321F1 /* OutlineViewSnapshotMember.swift in Sources */, 392 | ); 393 | runOnlyForDeploymentPostprocessing = 0; 394 | }; 395 | 0E76A68F23EEE5CD007321F1 /* Sources */ = { 396 | isa = PBXSourcesBuildPhase; 397 | buildActionMask = 2147483647; 398 | files = ( 399 | 0E76A69923EEE5CD007321F1 /* OutlineViewDiffableDataSourceTests.swift in Sources */, 400 | 0E0BABD823F19B5D00A3428F /* ArrayDataSource.swift in Sources */, 401 | 0E0BABD623F19AFF00A3428F /* OutlineViewSnapshotTests.swift in Sources */, 402 | ); 403 | runOnlyForDeploymentPostprocessing = 0; 404 | }; 405 | /* End PBXSourcesBuildPhase section */ 406 | 407 | /* Begin PBXTargetDependency section */ 408 | 0E6344BB23F2B3DC00870976 /* PBXTargetDependency */ = { 409 | isa = PBXTargetDependency; 410 | target = 0E6344A723F2B3D900870976 /* OutlineTest */; 411 | targetProxy = 0E6344BA23F2B3DC00870976 /* PBXContainerItemProxy */; 412 | }; 413 | 0E76A69623EEE5CD007321F1 /* PBXTargetDependency */ = { 414 | isa = PBXTargetDependency; 415 | target = 0E76A68923EEE5CD007321F1 /* OutlineViewDiffableDataSource */; 416 | targetProxy = 0E76A69523EEE5CD007321F1 /* PBXContainerItemProxy */; 417 | }; 418 | /* End PBXTargetDependency section */ 419 | 420 | /* Begin PBXVariantGroup section */ 421 | 0E6344B023F2B3DC00870976 /* Main.storyboard */ = { 422 | isa = PBXVariantGroup; 423 | children = ( 424 | 0E6344B123F2B3DC00870976 /* Base */, 425 | ); 426 | name = Main.storyboard; 427 | sourceTree = ""; 428 | }; 429 | /* End PBXVariantGroup section */ 430 | 431 | /* Begin XCBuildConfiguration section */ 432 | 0E6344C023F2B3DC00870976 /* Debug */ = { 433 | isa = XCBuildConfiguration; 434 | buildSettings = { 435 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 436 | CODE_SIGN_ENTITLEMENTS = OutlineTest/OutlineTest.entitlements; 437 | CODE_SIGN_STYLE = Automatic; 438 | COMBINE_HIDPI_IMAGES = YES; 439 | DEVELOPMENT_TEAM = LPR82YBESG; 440 | INFOPLIST_FILE = OutlineTest/Info.plist; 441 | LD_RUNPATH_SEARCH_PATHS = ( 442 | "$(inherited)", 443 | "@executable_path/../Frameworks", 444 | ); 445 | PRODUCT_BUNDLE_IDENTIFIER = com.bignerdranch.OutlineTest; 446 | PRODUCT_NAME = "$(TARGET_NAME)"; 447 | SWIFT_VERSION = 5.0; 448 | }; 449 | name = Debug; 450 | }; 451 | 0E6344C123F2B3DC00870976 /* Release */ = { 452 | isa = XCBuildConfiguration; 453 | buildSettings = { 454 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 455 | CODE_SIGN_ENTITLEMENTS = OutlineTest/OutlineTest.entitlements; 456 | CODE_SIGN_STYLE = Automatic; 457 | COMBINE_HIDPI_IMAGES = YES; 458 | DEVELOPMENT_TEAM = LPR82YBESG; 459 | INFOPLIST_FILE = OutlineTest/Info.plist; 460 | LD_RUNPATH_SEARCH_PATHS = ( 461 | "$(inherited)", 462 | "@executable_path/../Frameworks", 463 | ); 464 | PRODUCT_BUNDLE_IDENTIFIER = com.bignerdranch.OutlineTest; 465 | PRODUCT_NAME = "$(TARGET_NAME)"; 466 | SWIFT_VERSION = 5.0; 467 | }; 468 | name = Release; 469 | }; 470 | 0E6344C223F2B3DC00870976 /* Debug */ = { 471 | isa = XCBuildConfiguration; 472 | buildSettings = { 473 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 474 | BUNDLE_LOADER = "$(TEST_HOST)"; 475 | CODE_SIGN_STYLE = Automatic; 476 | COMBINE_HIDPI_IMAGES = YES; 477 | DEVELOPMENT_TEAM = LPR82YBESG; 478 | INFOPLIST_FILE = OutlineTestTests/Info.plist; 479 | LD_RUNPATH_SEARCH_PATHS = ( 480 | "$(inherited)", 481 | "@executable_path/../Frameworks", 482 | "@loader_path/../Frameworks", 483 | ); 484 | PRODUCT_BUNDLE_IDENTIFIER = com.bignerdranch.OutlineTestTests; 485 | PRODUCT_NAME = "$(TARGET_NAME)"; 486 | SWIFT_VERSION = 5.0; 487 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/OutlineTest.app/Contents/MacOS/OutlineTest"; 488 | }; 489 | name = Debug; 490 | }; 491 | 0E6344C323F2B3DC00870976 /* Release */ = { 492 | isa = XCBuildConfiguration; 493 | buildSettings = { 494 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 495 | BUNDLE_LOADER = "$(TEST_HOST)"; 496 | CODE_SIGN_STYLE = Automatic; 497 | COMBINE_HIDPI_IMAGES = YES; 498 | DEVELOPMENT_TEAM = LPR82YBESG; 499 | INFOPLIST_FILE = OutlineTestTests/Info.plist; 500 | LD_RUNPATH_SEARCH_PATHS = ( 501 | "$(inherited)", 502 | "@executable_path/../Frameworks", 503 | "@loader_path/../Frameworks", 504 | ); 505 | PRODUCT_BUNDLE_IDENTIFIER = com.bignerdranch.OutlineTestTests; 506 | PRODUCT_NAME = "$(TARGET_NAME)"; 507 | SWIFT_VERSION = 5.0; 508 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/OutlineTest.app/Contents/MacOS/OutlineTest"; 509 | }; 510 | name = Release; 511 | }; 512 | 0E76A69C23EEE5CD007321F1 /* Debug */ = { 513 | isa = XCBuildConfiguration; 514 | buildSettings = { 515 | ALWAYS_SEARCH_USER_PATHS = NO; 516 | CLANG_ANALYZER_NONNULL = YES; 517 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 518 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 519 | CLANG_CXX_LIBRARY = "libc++"; 520 | CLANG_ENABLE_MODULES = YES; 521 | CLANG_ENABLE_OBJC_ARC = YES; 522 | CLANG_ENABLE_OBJC_WEAK = YES; 523 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 524 | CLANG_WARN_BOOL_CONVERSION = YES; 525 | CLANG_WARN_COMMA = YES; 526 | CLANG_WARN_CONSTANT_CONVERSION = YES; 527 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 528 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 529 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 530 | CLANG_WARN_EMPTY_BODY = YES; 531 | CLANG_WARN_ENUM_CONVERSION = YES; 532 | CLANG_WARN_INFINITE_RECURSION = YES; 533 | CLANG_WARN_INT_CONVERSION = YES; 534 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 535 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 536 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 537 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 538 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 539 | CLANG_WARN_STRICT_PROTOTYPES = YES; 540 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 541 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 542 | CLANG_WARN_UNREACHABLE_CODE = YES; 543 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 544 | CODE_SIGN_IDENTITY = "Mac Developer"; 545 | COPY_PHASE_STRIP = NO; 546 | CURRENT_PROJECT_VERSION = 1; 547 | DEBUG_INFORMATION_FORMAT = dwarf; 548 | ENABLE_STRICT_OBJC_MSGSEND = YES; 549 | ENABLE_TESTABILITY = YES; 550 | GCC_C_LANGUAGE_STANDARD = gnu11; 551 | GCC_DYNAMIC_NO_PIC = NO; 552 | GCC_NO_COMMON_BLOCKS = YES; 553 | GCC_OPTIMIZATION_LEVEL = 0; 554 | GCC_PREPROCESSOR_DEFINITIONS = ( 555 | "DEBUG=1", 556 | "$(inherited)", 557 | ); 558 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 559 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 560 | GCC_WARN_UNDECLARED_SELECTOR = YES; 561 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 562 | GCC_WARN_UNUSED_FUNCTION = YES; 563 | GCC_WARN_UNUSED_VARIABLE = YES; 564 | MACOSX_DEPLOYMENT_TARGET = 10.15; 565 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 566 | MTL_FAST_MATH = YES; 567 | ONLY_ACTIVE_ARCH = YES; 568 | SDKROOT = macosx; 569 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 570 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 571 | VERSIONING_SYSTEM = "apple-generic"; 572 | VERSION_INFO_PREFIX = ""; 573 | }; 574 | name = Debug; 575 | }; 576 | 0E76A69D23EEE5CD007321F1 /* Release */ = { 577 | isa = XCBuildConfiguration; 578 | buildSettings = { 579 | ALWAYS_SEARCH_USER_PATHS = NO; 580 | CLANG_ANALYZER_NONNULL = YES; 581 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 582 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 583 | CLANG_CXX_LIBRARY = "libc++"; 584 | CLANG_ENABLE_MODULES = YES; 585 | CLANG_ENABLE_OBJC_ARC = YES; 586 | CLANG_ENABLE_OBJC_WEAK = YES; 587 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 588 | CLANG_WARN_BOOL_CONVERSION = YES; 589 | CLANG_WARN_COMMA = YES; 590 | CLANG_WARN_CONSTANT_CONVERSION = YES; 591 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 592 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 593 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 594 | CLANG_WARN_EMPTY_BODY = YES; 595 | CLANG_WARN_ENUM_CONVERSION = YES; 596 | CLANG_WARN_INFINITE_RECURSION = YES; 597 | CLANG_WARN_INT_CONVERSION = YES; 598 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 599 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 600 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 601 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 602 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 603 | CLANG_WARN_STRICT_PROTOTYPES = YES; 604 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 605 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 606 | CLANG_WARN_UNREACHABLE_CODE = YES; 607 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 608 | CODE_SIGN_IDENTITY = "Mac Developer"; 609 | COPY_PHASE_STRIP = NO; 610 | CURRENT_PROJECT_VERSION = 1; 611 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 612 | ENABLE_NS_ASSERTIONS = NO; 613 | ENABLE_STRICT_OBJC_MSGSEND = YES; 614 | GCC_C_LANGUAGE_STANDARD = gnu11; 615 | GCC_NO_COMMON_BLOCKS = YES; 616 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 617 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 618 | GCC_WARN_UNDECLARED_SELECTOR = YES; 619 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 620 | GCC_WARN_UNUSED_FUNCTION = YES; 621 | GCC_WARN_UNUSED_VARIABLE = YES; 622 | MACOSX_DEPLOYMENT_TARGET = 10.15; 623 | MTL_ENABLE_DEBUG_INFO = NO; 624 | MTL_FAST_MATH = YES; 625 | SDKROOT = macosx; 626 | SWIFT_COMPILATION_MODE = wholemodule; 627 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 628 | VERSIONING_SYSTEM = "apple-generic"; 629 | VERSION_INFO_PREFIX = ""; 630 | }; 631 | name = Release; 632 | }; 633 | 0E76A69F23EEE5CD007321F1 /* Debug */ = { 634 | isa = XCBuildConfiguration; 635 | buildSettings = { 636 | CLANG_ENABLE_MODULES = YES; 637 | CODE_SIGN_IDENTITY = ""; 638 | CODE_SIGN_STYLE = Automatic; 639 | COMBINE_HIDPI_IMAGES = YES; 640 | DEFINES_MODULE = YES; 641 | DEVELOPMENT_TEAM = LPR82YBESG; 642 | DYLIB_COMPATIBILITY_VERSION = 1; 643 | DYLIB_CURRENT_VERSION = 1; 644 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 645 | FRAMEWORK_VERSION = A; 646 | INFOPLIST_FILE = Info.plist; 647 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 648 | LD_RUNPATH_SEARCH_PATHS = ( 649 | "$(inherited)", 650 | "@executable_path/../Frameworks", 651 | "@loader_path/Frameworks", 652 | ); 653 | PRODUCT_BUNDLE_IDENTIFIER = com.bignerdranch.OutlineViewDiffableDataSource; 654 | PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; 655 | SKIP_INSTALL = YES; 656 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 657 | SWIFT_VERSION = 5.0; 658 | }; 659 | name = Debug; 660 | }; 661 | 0E76A6A023EEE5CD007321F1 /* Release */ = { 662 | isa = XCBuildConfiguration; 663 | buildSettings = { 664 | CLANG_ENABLE_MODULES = YES; 665 | CODE_SIGN_IDENTITY = ""; 666 | CODE_SIGN_STYLE = Automatic; 667 | COMBINE_HIDPI_IMAGES = YES; 668 | DEFINES_MODULE = YES; 669 | DEVELOPMENT_TEAM = LPR82YBESG; 670 | DYLIB_COMPATIBILITY_VERSION = 1; 671 | DYLIB_CURRENT_VERSION = 1; 672 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 673 | FRAMEWORK_VERSION = A; 674 | INFOPLIST_FILE = Info.plist; 675 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 676 | LD_RUNPATH_SEARCH_PATHS = ( 677 | "$(inherited)", 678 | "@executable_path/../Frameworks", 679 | "@loader_path/Frameworks", 680 | ); 681 | PRODUCT_BUNDLE_IDENTIFIER = com.bignerdranch.OutlineViewDiffableDataSource; 682 | PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; 683 | SKIP_INSTALL = YES; 684 | SWIFT_VERSION = 5.0; 685 | }; 686 | name = Release; 687 | }; 688 | 0E76A6A223EEE5CD007321F1 /* Debug */ = { 689 | isa = XCBuildConfiguration; 690 | buildSettings = { 691 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 692 | CODE_SIGN_STYLE = Automatic; 693 | COMBINE_HIDPI_IMAGES = YES; 694 | DEVELOPMENT_TEAM = LPR82YBESG; 695 | INFOPLIST_FILE = OutlineViewDiffableDataSourceTests/Info.plist; 696 | LD_RUNPATH_SEARCH_PATHS = ( 697 | "$(inherited)", 698 | "@executable_path/../Frameworks", 699 | "@loader_path/../Frameworks", 700 | ); 701 | PRODUCT_BUNDLE_IDENTIFIER = com.bignerdranch.OutlineViewDiffableDataSourceTests; 702 | PRODUCT_NAME = "$(TARGET_NAME)"; 703 | SWIFT_VERSION = 5.0; 704 | }; 705 | name = Debug; 706 | }; 707 | 0E76A6A323EEE5CD007321F1 /* Release */ = { 708 | isa = XCBuildConfiguration; 709 | buildSettings = { 710 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 711 | CODE_SIGN_STYLE = Automatic; 712 | COMBINE_HIDPI_IMAGES = YES; 713 | DEVELOPMENT_TEAM = LPR82YBESG; 714 | INFOPLIST_FILE = OutlineViewDiffableDataSourceTests/Info.plist; 715 | LD_RUNPATH_SEARCH_PATHS = ( 716 | "$(inherited)", 717 | "@executable_path/../Frameworks", 718 | "@loader_path/../Frameworks", 719 | ); 720 | PRODUCT_BUNDLE_IDENTIFIER = com.bignerdranch.OutlineViewDiffableDataSourceTests; 721 | PRODUCT_NAME = "$(TARGET_NAME)"; 722 | SWIFT_VERSION = 5.0; 723 | }; 724 | name = Release; 725 | }; 726 | /* End XCBuildConfiguration section */ 727 | 728 | /* Begin XCConfigurationList section */ 729 | 0E6344C423F2B3DC00870976 /* Build configuration list for PBXNativeTarget "OutlineTest" */ = { 730 | isa = XCConfigurationList; 731 | buildConfigurations = ( 732 | 0E6344C023F2B3DC00870976 /* Debug */, 733 | 0E6344C123F2B3DC00870976 /* Release */, 734 | ); 735 | defaultConfigurationIsVisible = 0; 736 | defaultConfigurationName = Release; 737 | }; 738 | 0E6344C523F2B3DC00870976 /* Build configuration list for PBXNativeTarget "OutlineTestTests" */ = { 739 | isa = XCConfigurationList; 740 | buildConfigurations = ( 741 | 0E6344C223F2B3DC00870976 /* Debug */, 742 | 0E6344C323F2B3DC00870976 /* Release */, 743 | ); 744 | defaultConfigurationIsVisible = 0; 745 | defaultConfigurationName = Release; 746 | }; 747 | 0E76A68423EEE5CD007321F1 /* Build configuration list for PBXProject "OutlineViewDiffableDataSource" */ = { 748 | isa = XCConfigurationList; 749 | buildConfigurations = ( 750 | 0E76A69C23EEE5CD007321F1 /* Debug */, 751 | 0E76A69D23EEE5CD007321F1 /* Release */, 752 | ); 753 | defaultConfigurationIsVisible = 0; 754 | defaultConfigurationName = Release; 755 | }; 756 | 0E76A69E23EEE5CD007321F1 /* Build configuration list for PBXNativeTarget "OutlineViewDiffableDataSource" */ = { 757 | isa = XCConfigurationList; 758 | buildConfigurations = ( 759 | 0E76A69F23EEE5CD007321F1 /* Debug */, 760 | 0E76A6A023EEE5CD007321F1 /* Release */, 761 | ); 762 | defaultConfigurationIsVisible = 0; 763 | defaultConfigurationName = Release; 764 | }; 765 | 0E76A6A123EEE5CD007321F1 /* Build configuration list for PBXNativeTarget "OutlineViewDiffableDataSourceTests" */ = { 766 | isa = XCConfigurationList; 767 | buildConfigurations = ( 768 | 0E76A6A223EEE5CD007321F1 /* Debug */, 769 | 0E76A6A323EEE5CD007321F1 /* Release */, 770 | ); 771 | defaultConfigurationIsVisible = 0; 772 | defaultConfigurationName = Release; 773 | }; 774 | /* End XCConfigurationList section */ 775 | }; 776 | rootObject = 0E76A68123EEE5CD007321F1 /* Project object */; 777 | } 778 | -------------------------------------------------------------------------------- /OutlineViewDiffableDataSource.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /OutlineViewDiffableDataSourceTests/ArrayDataSource.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ArrayDataSource.swift 3 | // OutlineViewDiffableDataSourceTests 4 | // 5 | // Created by Steve Sparks on 2/10/20. 6 | // Copyright © 2020 Big Nerd Ranch. All rights reserved. 7 | // 8 | 9 | import Cocoa 10 | 11 | /*** 12 | * This simple data source lets you stash an array of items 13 | */ 14 | class ArrayDataSource: NSObject, NSOutlineViewDataSource { 15 | static let RootIdentfier = UUID().uuidString 16 | 17 | var root: [AnyHashable] { 18 | get { return contents[ArrayDataSource.RootIdentfier]! } 19 | set { contents[ArrayDataSource.RootIdentfier] = newValue } 20 | } 21 | 22 | var contents: [AnyHashable: [AnyHashable]] = [ArrayDataSource.RootIdentfier:[]] 23 | func outlineView(_ outlineView: NSOutlineView, child index: Int, ofItem item: Any?) -> Any { 24 | if let item = item as? String, let arr = contents[item] { 25 | return arr[index] 26 | } else { 27 | return root[index] 28 | } 29 | } 30 | 31 | func outlineView(_ outlineView: NSOutlineView, numberOfChildrenOfItem item: Any?) -> Int { 32 | if let item = item as? String { 33 | return contents[item]?.count ?? 0 34 | } else { 35 | return root.count 36 | } 37 | } 38 | 39 | func outlineView(_ outlineView: NSOutlineView, isItemExpandable item: Any) -> Bool { 40 | if let item = item as? String { 41 | return (contents[item]?.count ?? 0) > 0 42 | } 43 | return false 44 | } 45 | 46 | public func remove(_ val: AnyHashable) -> (AnyHashable, Int)? { 47 | for (k, v) in contents { 48 | if let idx = v.firstIndex(of: val) { 49 | var m = v 50 | m.remove(at: idx) 51 | contents[k] = m.isEmpty ? nil : m 52 | return (k, idx) 53 | } 54 | } 55 | return nil 56 | } 57 | } 58 | 59 | extension ArrayDataSource: NSOutlineViewDelegate { 60 | func outlineView(_ outlineView: NSOutlineView, viewFor tableColumn: NSTableColumn?, item: Any) -> NSView? { 61 | return NSTextField(labelWithString: String(describing: item)) 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /OutlineViewDiffableDataSourceTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /OutlineViewDiffableDataSourceTests/OutlineViewDiffableDataSourceTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // OutlineViewDiffableDataSourceTests.swift 3 | // OutlineViewDiffableDataSourceTests 4 | // 5 | // Created by Steve Sparks on 2/8/20. 6 | // Copyright © 2020 Big Nerd Ranch. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | @testable import OutlineViewDiffableDataSource 11 | 12 | class OutlineViewDiffableDataSourceTests: XCTestCase { 13 | 14 | override func setUp() { 15 | // Put setup code here. This method is called before the invocation of each test method in the class. 16 | } 17 | 18 | override func tearDown() { 19 | // Put teardown code here. This method is called after the invocation of each test method in the class. 20 | } 21 | 22 | func testExample() { 23 | // This is an example of a functional test case. 24 | // Use XCTAssert and related functions to verify your tests produce the correct results. 25 | } 26 | 27 | func testPerformanceExample() { 28 | // This is an example of a performance test case. 29 | self.measure { 30 | // Put the code you want to measure the time of here. 31 | } 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /OutlineViewDiffableDataSourceTests/OutlineViewSnapshotTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // OutlineViewSnapshotTests.swift 3 | // OutlineViewDiffableDataSourceTests 4 | // 5 | // Created by Steve Sparks on 2/10/20. 6 | // Copyright © 2020 Big Nerd Ranch. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | @testable import OutlineViewDiffableDataSource 11 | 12 | class OutlineViewSnapshotTests: XCTestCase { 13 | let dataSource = ArrayDataSource() 14 | let outlineView = NSOutlineView() 15 | 16 | override func setUp() { 17 | // Put setup code here. This method is called before the invocation of each test method in the class. 18 | } 19 | 20 | override func tearDown() { 21 | // Put teardown code here. This method is called after the invocation of each test method in the class. 22 | } 23 | 24 | func testInsertInstructions() { 25 | dataSource.contents = [ 26 | ArrayDataSource.RootIdentfier: ["A", "B"], 27 | "A": ["A1", "A2"], 28 | "A1": ["A1a", "A1b"], 29 | "B": ["B1", "B2"], 30 | "B2": ["B2b"] 31 | ] 32 | 33 | let firstSnapshot = OutlineViewSnapshot(from: dataSource, for: outlineView) 34 | dataSource.contents["B"] = ["B1", "B1A", "B2"] 35 | let secondSnapshot = OutlineViewSnapshot(from: dataSource, for: outlineView) 36 | 37 | let instructions = firstSnapshot.instructions(forMorphingInto: secondSnapshot) 38 | XCTAssertEqual(instructions.count, 1, "Didn't pan out") 39 | XCTAssertEqual(instructions.first?.description, "Inserting @ [1, 1]: ") 40 | } 41 | 42 | func testRemoveInstructions() { 43 | dataSource.contents = [ 44 | ArrayDataSource.RootIdentfier: ["A", "B"], 45 | "A": ["A1", "A2"], 46 | "A1": ["A1a", "A1b"], 47 | "B": ["B1", "B2"], 48 | "B2": ["B2b"] 49 | ] 50 | 51 | let firstSnapshot = OutlineViewSnapshot(from: dataSource, for: outlineView) 52 | dataSource.contents["B"] = ["B1"] 53 | let secondSnapshot = OutlineViewSnapshot(from: dataSource, for: outlineView) 54 | 55 | let instructions = firstSnapshot.instructions(forMorphingInto: secondSnapshot) 56 | XCTAssertEqual(instructions.count, 1, "Didn't pan out") 57 | XCTAssertEqual(instructions.first?.description, "Removing @ [1, 1]") 58 | } 59 | 60 | func testMoveInstructions() { 61 | dataSource.contents = [ 62 | ArrayDataSource.RootIdentfier: ["A", "B"], 63 | "A": ["A1", "A2"], 64 | "A1": ["A1a", "A1b"], 65 | "B": ["B1", "B2"], 66 | "B2": ["B2b"] 67 | ] 68 | 69 | let firstSnapshot = OutlineViewSnapshot(from: dataSource, for: outlineView) 70 | dataSource.contents["B"] = ["B2", "B1"] 71 | let secondSnapshot = OutlineViewSnapshot(from: dataSource, for: outlineView) 72 | 73 | let instructions = firstSnapshot.instructions(forMorphingInto: secondSnapshot) 74 | XCTAssertEqual(instructions.count, 1, "Didn't pan out") 75 | XCTAssertEqual(instructions.first?.description, "Move from [1, 1] to [1, 0]") 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # OutlineViewDiffableDataSource 2 | Cocoa NSOutlineView version of diffable data sources in iOS 13 3 | 4 | ### Usage 5 | 6 | Initialize a data source and send it its own `NSOutlineViewDataSource` and `NSOutlineViewDelegate` to pass through the calls. 7 | 8 | When you call `applySnapshot()` on the diffable data source instead of `reloadData()`, it appropriately animates all the cells to their new locations. 9 | 10 | ![Sample app](diff.gif) 11 | 12 | ### To Do 13 | 14 | - Perhaps honor the `responds(to: selector)` stuff in the data source. I began this, but it wasn't necessary, so I punted. 15 | - Passthrough implementations of all the remaining delegate methods 16 | -------------------------------------------------------------------------------- /diff.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stevesparks/OutlineViewDiffableDataSource/6803c470e60d46409573162cc6cca1c4eed0938a/diff.gif --------------------------------------------------------------------------------