Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Stop looking for NSOutlineViewDiffableDataSource, it’s here 👌

License

NotificationsYou must be signed in to change notification settings

BeehiveInnovations/OutlineViewDiffableDataSource

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Here’s to the crazy ones…

At WWDC 2019 Apple introduced amazing APIs forUITableView andUICollectionView data management. For instance, the barely documentedUITableViewDiffableDataSource can be used as a data source of a table view, and all modifications made to itsNSDiffableDataSourceSnapshot are automatically applied by that table view.

Watch the official video“Advances in UI Data Sources” to get a better idea.

These diffable APIs were fantastic news for UIKit Developers. Unfortunately AppKit has got onlyNSCollectionViewDiffableDataSource andNSTableViewDiffableDataSource which means thatNSOutlineView is out of luck. Let’s hope that Apple releasesNSOutlineViewDiffableDataSource at WWDC21.

OutlineViewDiffableDataSource

This Swift Package is my modest attempt to implement a diffable data source forNSOutlineView with support for nested items. This is how it’s used:

letdataSource=OutlineViewDiffableDataSource(outlineView: outlineView)varsnapshot= dataSource.snapshot()snapshot.appendItems([folder1, folder2])snapshot.appendItems([file11, file12], into: folder1)snapshot.appendItems([file21, file22], into: folder2)dataSource.applySnapshot(initialSnapshot, animatingDifferences:false)

The accompanyingDiffableDataSourceSnapshot API is heavily inspired by Cocoa’s ownNSDiffableDataSourceSnapshot and includes many similar methods, but adopted for tree data structures:

// …mutatingfunc insertItems(_ newItems:[Item], beforeItem:Item)-> Boolmutatingfunc insertItems(_ newItems:[Item], afterItem:Item)-> Boolmutatingfunc deleteItems(_ existingItems:[Item])->Boolmutatingfunc deleteAllItems()mutatingfunc reloadItems(_ items:[Item])->Bool// …

Not sure how this ends, but theDiffableDataSourceSnapshot is a value type. Just like its “official” counterpart, this struct can be built and applied from the background thread, as far as I know 😅

Requirements

SPM: macOS 10.11

Demo: macOS 10.15

Demo App

The Demo Mac app is a playground for breaking the library. The snapshot API is 100% covered by Tests, but I would much appreciate any help with QA.

OutlineViewDiffableDataSource Demo

Help Wanted

If you download and play with the sample app, it’s already cool. But if you report or even fix one of the issues, you are just awesome. Here is a Roadmap, please join me if you can:

  • Add a new section “Quick Start”
  • Explain the protocolOutlineViewItem
  • Explain how to implement drag-n-drop in your app
  • Add versioning because now it’s just amaster branch
  • Add this project to theDave’s repository of Swift Packages
  • Improve the Demo app, it’s too basic and doesn’t show all the features
  • File a Radar requesting a realNSOutlineViewDiffableDataSource, why not
  • Make a profile picture from one of WWDC slides about diffable data sources
  • Generate documentation usingSwift Doc
  • Add badges like “Swift 5.2” and “CI Passing”
  • Fill theCommunity Profile
  • Add Showcase section if anyone uses this component

Contact Information

You can always find me as@VadimShpakovski in Twitter. If you publish apps in the App Store or in the Mac App Store, check out my native client for the App Store Connect:NativeConnect. Some people like it. Thanks in advance!

About

Stop looking for NSOutlineViewDiffableDataSource, it’s here 👌

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Swift100.0%

[8]ページ先頭

©2009-2025 Movatter.jp