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

💾 A library for backporting UITableView/UICollectionViewDiffableDataSource.

License

NotificationsYou must be signed in to change notification settings

ra1028/DiffableDataSources

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

💾 A library for backporting UITableView/UICollectionViewDiffableDataSource
powered byDifferenceKit.

Swift5ReleaseCocoaPodsCarthageSwift Package Manager
Build StatusPlatformLincense

Made with ❤️ byRyo Aoyama


Introduction

Apple has announced a diffable data source at WWDC 2019.
It's a great API that easily updating our table view and collection view items using automatic diffing.
However, it's a little while before we can use it in a production service.
That because it requires the latest OS to use.
DiffableDataSources make it possible to introduce almost the same functionality from now on.

Uses a sophisticated open sourceDifferenceKit for the algorithm engine.
It's extremely fast and completely avoids synchronization bugs, exceptions, and crashes.



Difference from the Official

Spec

  • Supports iOS 9.0+ / macOS 10.11+ / tvOS 9.0+
  • Open sourced algorithm.
  • Duplicate sections or items are allowed.
  • UsingperformBatchUpdates for diffing updates.

Namings

DiffableDataSources have different class names to avoid conflicts with the official API.
Correspondence table is below.

OfficialBackported
NSDiffableDataSourceSnapshotDiffableDataSourceSnapshot
UITableViewDiffableDataSourceTableViewDiffableDataSource
UICollectionViewDiffableDataSourceCollectionViewDiffableDataSource
NSCollectionViewDiffableDataSourceCocoaCollectionViewDiffableDataSource

Getting Started

Build Project

$ git clone https://github.com/ra1028/DiffableDataSources.git$cd DiffableDataSources/$ make setup$ open DiffableDataSources.xcworkspace

Basic Usage

First, define the type representing section.
It should conforms toHashable for identifies from the all sections.
Type of enum can used conveniently because it conformsHashable by default.

enumSection{case main}

Then, define the item type conforms toHashable.

structUser:Hashable{varname:String}

Create a data source object, it will be set to table view automatically.
You should dequeue the non nil cells via closure.

finalclassUsersViewController:UIViewController{lettableView:UITableView=...    lazyvardataSource=TableViewDiffableDataSource<Section,User>(tableView: tableView){ tableView, indexPath, userinletcell= tableView.dequeueReusableCell(withIdentifier:"Cell", for: indexPath)        cell.textLabel?.text= user.namereturn cell}overridefunc viewDidLoad(){        super.viewDidLoad()        tableView.register(UITableViewCell.self, forCellReuseIdentifier:"Cell")}}

Manages and updates the data sources intuitively by intermediatingDiffableDataSourceSnapshot.
The UI isn't updated until you apply the edited snapshot object.
Update the UI with diffing animation automatically calculated by applying an edited snapshot.

letusers=[User(name:"Steve Jobs"),User(name:"Stephen Wozniak"),User(name:"Tim Cook"),User(name:"Jonathan Ive")]letsnapshot=DiffableDataSourceSnapshot<Section,User>()snapshot.appendSections([.main])snapshot.appendItems(users)dataSource.apply(snapshot){    // completion}

Check the documentation for more detailed API.


Requirements

  • Swift 5.0+
  • iOS 9.0+
  • macOS 10.11+
  • tvOS 9.0+

Installation

Add the following to yourPodfile:

pod'DiffableDataSources'

Add the following to yourCartfile:

github "ra1028/DiffableDataSources"

Add the following to the dependencies of yourPackage.swift:

.package(url:"https://github.com/ra1028/DiffableDataSources.git", from:"x.x.x")

Contributing

Pull requests, bug reports and feature requests are welcome 🚀
Please see theCONTRIBUTING file for learn how to contribute to DiffableDataSources.


Relations

A fast and flexible O(n) difference algorithm framework for Swift collection.

A declarative library for building component-based user interfaces in UITableView and UICollectionView.


License

DiffableDataSources is released under theApache 2.0 License.

About

💾 A library for backporting UITableView/UICollectionViewDiffableDataSource.

Topics

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Packages

No packages published

Contributors10


[8]ページ先頭

©2009-2025 Movatter.jp