Code Monkey home page Code Monkey logo

outlineviewdiffabledatasource's Introduction

Here’s to the crazy ones…

Introduction

At WWDC 2019 Apple introduced amazing APIs for UITableView and UICollectionView data management. For instance, the barely documented UITableViewDiffableDataSource can be used as a data source of a table view, and all modifications made to its NSDiffableDataSourceSnapshot 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 only NSCollectionViewDiffableDataSource and NSTableViewDiffableDataSource which means that NSOutlineView is out of luck. Let’s hope that Apple releases NSOutlineViewDiffableDataSource at WWDC21.

OutlineViewDiffableDataSource

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

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

The accompanying DiffableDataSourceSnapshot API is heavily inspired by Cocoa’s own NSDiffableDataSourceSnapshot and includes many similar methods, but adopted for tree data structures:

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

Not sure how this ends, but the DiffableDataSourceSnapshot 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 😅

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 protocol OutlineViewItem
  • Explain how to implement drag-n-drop in your app
  • Add versioning because now it’s just a master branch
  • Add this project to the Dave’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 real NSOutlineViewDiffableDataSource, why not
  • Make a profile picture from one of WWDC slides about diffable data sources
  • Generate documentation using Swift Doc
  • Add badges like “Swift 5.2” and “CI Passing”
  • Fill the Community 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!

outlineviewdiffabledatasource's People

Contributors

dezinezync avatar rinsuki avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.