Coder Social home page Coder Social logo

ra1028 / diffabledatasources Goto Github PK

View Code? Open in Web Editor NEW
843.0 11.0 67.0 4.22 MB

πŸ’Ύ A library for backporting UITableView/UICollectionViewDiffableDataSource.

Home Page: https://ra1028.github.io/DiffableDataSources

License: Apache License 2.0

Swift 98.27% Makefile 0.31% Ruby 1.42%
tableview collectionview datasource diffable diffing diff algorithm wwdc19

diffabledatasources's Introduction

DiffableDataSources

πŸ’Ύ A library for backporting UITableView/UICollectionViewDiffableDataSource
powered by DifferenceKit.

Swift5 Release CocoaPods Carthage Swift Package Manager
Build Status Platform Lincense

Made with ❀️ by Ryo 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 source DifferenceKit 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.
  • Using performBatchUpdates for diffing updates.

Namings

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

Official Backported
NSDiffableDataSourceSnapshot DiffableDataSourceSnapshot
UITableViewDiffableDataSource TableViewDiffableDataSource
UICollectionViewDiffableDataSource CollectionViewDiffableDataSource
NSCollectionViewDiffableDataSource CocoaCollectionViewDiffableDataSource

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 to Hashable for identifies from the all sections.
Type of enum can used conveniently because it conforms Hashable by default.

enum Section {
    case main
}

Then, define the item type conforms to Hashable.

struct User: Hashable {
    var name: String
}

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

final class UsersViewController: UIViewController {
    let tableView: UITableView = ...

    lazy var dataSource = TableViewDiffableDataSource<Section, User>(tableView: tableView) { tableView, indexPath, user in
        let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
        cell.textLabel?.text = user.name
        return cell
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        tableView.register(UITableViewCell.self, forCellReuseIdentifier: "Cell")
    }
}

Manages and updates the data sources intuitively by intermediating DiffableDataSourceSnapshot.
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.

let users = [
    User(name: "Steve Jobs"),
    User(name: "Stephen Wozniak"),
    User(name: "Tim Cook"),
    User(name: "Jonathan Ive")
]

let snapshot = 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 your Podfile:

pod 'DiffableDataSources'

Add the following to your Cartfile:

github "ra1028/DiffableDataSources"

Add the following to the dependencies of your Package.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 the CONTRIBUTING 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 the Apache 2.0 License.

diffabledatasources's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

diffabledatasources's Issues

Dear, please help me: I probably found a big bug, in iOS 10.3 and iOS 11, update datasource will not work correctly, please look at below.

Dear,

I use IBPCollectionViewCompositionalLayout in iOS 13 will no problem, but in iOS 10 and iOS 11 is not ok, please see the screenshot and the IBPCollectionViewCompositionalLayout.zip example that I sent to you below, run and select OrthogonalScrollBehaviorViewController.swift with iOS 10.3, the Xcode will crash.

Why it is, please help me, I take two days to debug this question, but no answer.

I put the demo.zip project on the Aliyun OSS, sincerely hope you can download the demo project and debug it.

Please download the demo: https://dxy-demo.oss-ap-northeast-1.aliyuncs.com/IBPCollectionViewCompositionalLayout.zip

Or the link of github: https://github.com/willokyes/IBPCollectionViewCompositionalLayout-Demo

I'm looking forward to your reply.

Thank you.

70385899-e38e5480-19cc-11ea-9e25-0b016531e582

Support for ARM64 Macs

Checklist

  • Reviewed the README and documents.
  • Searched existing issues for ensure not duplicated.

Description

DiffableDataSources should support ARM Macs.

Motivation and Context

DiffableDataSources currently only gets built for x86_64 for macOS and the Simulator. Now that all new Macs use an ARM CPU, DiffableDataSources should also be built for ARM.

Proposed Solution

Crash on iOS 11

Checklist

  • This is not a Apple's bug.
  • Reviewed the README and documents.
  • Searched existing issues for ensure not duplicated.

My app crashes on iOS 11, works fine on iOS 12 and iOS 13.

I'm using IBPCollectionViewCompositionalLayout.

Screenshot 2020-08-03 at 11 52 05

Detailed Description (Include Screenshots)

Stack Trace:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSDictionaryM setObject:forKey:]: key cannot be nil'
*** First throw call stack:
(
	0   CoreFoundation                      0x000000011c13e1e6 __exceptionPreprocess + 294
	1   libobjc.A.dylib                     0x000000011b7d3031 objc_exception_throw + 48
	2   CoreFoundation                      0x000000011c17e0bc _CFThrowFormattedException + 194
	3   CoreFoundation                      0x000000011c05172a -[__NSDictionaryM setObject:forKey:] + 1002
	4   UIKit                               0x0000000118990f07 -[UICollectionView _setVisibleView:forLayoutAttributes:] + 171
	5   UIKit                               0x00000001189a9dcb __71-[UICollectionView _updateWithItems:tentativelyForReordering:animator:]_block_invoke.1997 + 744
	6   UIKit                               0x0000000117f85537 +[UIView(UIViewAnimationWithBlocks) _setupAnimationWithDuration:delay:view:options:factory:animations:start:animationStateGenerator:completion:] + 560
	7   UIKit                               0x0000000117f85a0f +[UIView(UIViewAnimationWithBlocks) animateWithDuration:delay:options:animations:completion:] + 99
	8   UIKit                               0x00000001189a90f5 -[UICollectionView _updateWithItems:tentativelyForReordering:animator:] + 6349
	9   UIKit                               0x00000001189a2cc3 -[UICollectionView _endItemAnimationsWithInvalidationContext:tentativelyForReordering:animator:] + 17420
	10  UIKit                               0x00000001189ab00e -[UICollectionView _endUpdatesWithInvalidationContext:tentativelyForReordering:animator:] + 71
	11  UIKit                               0x00000001189ab357 -[UICollectionView _performBatchUpdates:completion:invalidationContext:tentativelyForReordering:animator:] + 439
	12  UIKit                               0x00000001189ab17d -[UICollectionView _performBatchUpdates:completion:invalidationContext:tentativelyForReordering:] + 91
	13  UIKit                               0x00000001189ab0ff -[UICollectionView _performBatchUpdates:completion:invalidationContext:] + 74
	14  UIKit                               0x00000001189ab054 -[UICollectionView performBatchUpdates:completion:] + 53
	15  DifferenceKit                       0x00000001139ef434 $sSo16UICollectionViewC13DifferenceKitE6reload5using9interrupt7setDatayAC15StagedChangesetVyxG_SbAC0K0VyxGcSgyxXEtSlRzlF + 3188
	16  DiffableDataSources                 0x000000011397a15a $s19DiffableDataSources014CollectionViewaB6SourceC5apply_20animatingDifferences10completionyAA0abF8SnapshotVyxq_G_SbyycSgtFySo012UICollectionE0C_13DifferenceKit15StagedChangesetVySayAA0K9StructureV7SectionVyxq__GGGyAUctcfU_ + 1066
	17  DiffableDataSources                 0x000000011397a1fa $s19DiffableDataSources014CollectionViewaB6SourceC5apply_20animatingDifferences10completionyAA0abF8SnapshotVyxq_G_SbyycSgtFySo012UICollectionE0C_13DifferenceKit15StagedChangesetVySayAA0K9StructureV7SectionVyxq__GGGyAUctcfU_TA + 58
	18  DiffableDataSources                 0x000000011397e4d9 $s19DiffableDataSources0aB10SourceCoreC5apply_4view20animatingDifferences14performUpdates10completionyAA0abD8SnapshotVyxq_G_qd__SgSbyqd___13DifferenceKit15StagedChangesetVySayAA0M9StructureV7SectionVyxq__GGGyAUctcyycSgtRld__ClFyycfU_0j7DiffingK0L_yySHRzSHR_Rld__Cr0__lF + 649
	19  DiffableDataSources                 0x000000011397e03a $s19DiffableDataSources0aB10SourceCoreC5apply_4view20animatingDifferences14performUpdates10completionyAA0abD8SnapshotVyxq_G_qd__SgSbyqd___13DifferenceKit15StagedChangesetVySayAA0M9StructureV7SectionVyxq__GGGyAUctcyycSgtRld__ClFyycfU_ + 1242
	20  DiffableDataSources                 0x000000011397e237 $s19DiffableDataSources0aB10SourceCoreC5apply_4view20animatingDifferences14performUpdates10completionyAA0abD8SnapshotVyxq_G_qd__SgSbyqd___13DifferenceKit15StagedChangesetVySayAA0M9StructureV7SectionVyxq__GGGyAUctcyycSgtRld__ClFyycfU_TA + 135
	21  DiffableDataSources                 0x0000000113982979 $s19DiffableDataSources26MainThreadSerialDispatcherC8dispatchyyyycF + 361
	22  DiffableDataSources                 0x000000011397dadf $s19DiffableDataSources0aB10SourceCoreC5apply_4view20animatingDifferences14performUpdates10completionyAA0abD8SnapshotVyxq_G_qd__SgSbyqd___13DifferenceKit15StagedChangesetVySayAA0M9StructureV7SectionVyxq__GGGyAUctcyycSgtRld__ClF + 623
	23  DiffableDataSources                 0x0000000113979cef $s19DiffableDataSources014CollectionViewaB6SourceC5apply_20animatingDifferences10completionyAA0abF8SnapshotVyxq_G_SbyycSgtF + 335
	24  Stickers                            0x000000010f1bc81c $s8Stickers21GalleryViewControllerC9refreshUIyyFy19DiffableDataSources0gH14SourceSnapshotVyAA7SectionCAA4CellCG_s5Error_pSgtcfU_ + 924
	25  Stickers                            0x000000010f2b56dd $s8Stickers11GalleryDataC4load10completionyy08DiffableC7Sources0fC14SourceSnapshotVyAA7SectionCAA4CellCG_s5Error_pSgtc_tFyycfU4_ + 205
	26  Stickers                            0x000000010f161860 $sIeg_IeyB_TR + 48
	27  libdispatch.dylib                   0x000000011d1c97ab _dispatch_call_block_and_release + 12
	28  libdispatch.dylib                   0x000000011d1ca7ec _dispatch_client_callout + 8
	29  libdispatch.dylib                   0x000000011d1d58cf _dispatch_main_queue_callback_4CF + 628
	30  CoreFoundation                      0x000000011c100c99 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
	31  CoreFoundation                      0x000000011c0c4ea6 __CFRunLoopRun + 2342
	32  CoreFoundation                      0x000000011c0c430b CFRunLoopRunSpecific + 635
	33  GraphicsServices                    0x000000011e2bda73 GSEventRunModal + 62
	34  UIKit                               0x0000000117ec3057 UIApplicationMain + 159
	35  Stickers                            0x000000010f28a5cb main + 75
	36  libdyld.dylib                       0x000000011d247955 start + 1

Reproducible Demo Project

Environments

  • dependencies:

  - DiffableDataSources (0.4.0):
    - DifferenceKit/AppKitExtension (~> 1.1)
    - DifferenceKit/UIKitExtension (~> 1.1)
  - DifferenceKit/Core (1.1.5)
  - DifferenceKit/UIKitExtension (1.1.5):
    - DifferenceKit/Core
  • version: 0.4.0

  • Swift version: 5.0

  • iOS version: 11

  • Xcode version: 11.6

  • Devices/Simulators: Both

  • CocoaPods/Carthage version: cocoapods 1.9.3

We're unable to build in Release mode but you have a change on `master` that fixes the issue

Checklist

  • Reviewed the README and documents.
  • Searched existing issues for ensure not duplicated.

Expected Behavior

We should be able to build in Release mode.

Current Behavior

In Xcode 11.4 only, building the framework in Release mode fails. The error is in SnapshotStructure.swift on line 38: the compiler complains that it resolves Collection to SnapshotStructure.Section.Collection and that this type has no associated Element.

Detailed Description (Include Screenshots)

The change already made on master to Swift.Collection resolves this issue, but it's not yet in a release.

Please can you make a new release including this change?

Environment

  • version:

  • Swift version:

5.0

  • iOS version:

12.1/13.4

  • Xcode version:

11.4

  • Devices/Simulators:

Any

  • CocoaPods/Carthage version:

1.9.0.beta.2 (issue also occurs with latest SPM release)

Missing section identifier in UICollectionViewDelegate methods when deleting sections

Checklist

  • [YES] Reviewed the README and documents.
  • [YES] Searched existing issues for ensure not duplicated.

Description

When it's called just after applying deleted section

    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {

        // it crashes when it's called just after applying deleted section
        let sectionIdentifier1 = self.dataSource.snapshot().sectionIdentifiers[section]

        // it would be nice to have sth like this as data source is still correct when snapshot actually isn't
        let sectionIdentifier2 = self.dataSource.sectionIdentifier(for: section) 

        // I need to know which section is here
    }

then it crashes or it's not possible to get section identifier in UICollectionViewDelegate methods.

Add update support for diff algorithm

DifferenceKit use ContentEquatable protocol to produce items update. DataSource wrap items into struct which implement Differentiable protocol. In fact diff algorithm never produce update events, there is only one way - call reload method in DataSource. We would like to implement ContentEquatable for DataSource items and get ChangeSet with updates.

Broken swipe actions

Checklist

  • [x ] This is not a Apple's bug.
  • [x ] Reviewed the README and documents.
  • [x ] Searched existing issues for ensure not duplicated.

Expected Behavior

trailingSwipeActionsConfigurationForRowAt is called

Current Behavior

trailingSwipeActionsConfigurationForRowAt not called

Steps to Reproduce

  1. Create table view with diffable data source
  2. Implement table view delegate's method tableView( tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath)_
    )
  3. Set data source to diffable data source and delegate to self.
  4. See that it's not called

Environments

  • version:
    0.4.0
  • Swift version:
    5.2
  • iOS version:
    14.2
  • Xcode version:
    12.2
  • Devices/Simulators:
    iPhone 7/iPhone 11 Pro
  • CocoaPods/Carthage version:
    0.4.0

Missing UITableViewDiffableDataSource methods for edit/move rows

Thank you for creating this project, it's become really useful in few of my projects!

However I have noticed few methods from the official UITableViewDiffableDataSource are missing from your implementation:

  • func tableView(UITableView, canEditRowAt: IndexPath) -> Bool
  • func tableView(UITableView, canMoveRowAt: IndexPath) -> Bool
  • func tableView(UITableView, cellForRowAt: IndexPath) -> UITableViewCell
  • func tableView(UITableView, commit: UITableViewCell.EditingStyle, forRowAt: IndexPath)
  • func tableView(UITableView, moveRowAt: IndexPath, to: IndexPath)

Reference: https://developer.apple.com/documentation/uikit/uitableviewdiffabledatasource

Naturally I'd expect these methods to be open and overridable to be able to construct and apply a new snapshot separately.

Expected Behavior

Subclassing the TableViewDiffableDataSource should allow to override and provide a custom implementation for canEditRowAt/canMoveRowAt protocol methods.

class MyDiffableDataSource: TableViewDiffableDataSource<SectionViewModel, AnyViewModel> {
    func tableView(_: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
        return true
    }

    func tableView(_: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
        // Custom implementation
    }
}

Current Behavior

Methods canEditRowAt and commit:editingStyle:forRowAt do not get executed when implemented on a subclass. This is probably because the base class does not provide an open/public default implementations for these.

Item reloads are not calculated correctly

Hello!

First and foremost; γ“γ‚Œγ‚’δ½œγ£γ¦γγ‚Œγ¦γ€γ‚γ‚ŠγŒγ¨γ†γ”γ–γ„γΎγ™οΌεŠ©γ‹γ‚ŠγΎγ—γŸ πŸ™‡πŸ»β€β™‚οΈ

I have noticed a minor issue, which I have described below using the issue template. I've also forked this repo and applied a fix, which you can find here: https://github.com/simba909/DiffableDataSources

I would be happy to provide a pull request πŸ‘πŸ»

Checklist

  • This is not a Apple's bug.
  • Reviewed the README and documents.
  • Searched existing issues for ensure not duplicated.

Expected Behavior

When using this library and applying two snapshots after one another, I expect the two snapshots to be correctly differentiated like in Apple's NSDiffableDataSource so that item updates are correctly reflected between the two snapshots. Below is some sample code that demonstrates the use-case:

struct MyItem: Hashable, Equatable {
    let id: Int
    var name: String

    func hash(into hasher: inout Hasher) {
        hasher.combine(id)
    }
}

let snapshot = DiffableDataSourceSnapshot<Int, MyItem>()
snapshot.appendSections([0])

let myItem = MyItem(id: 1, name: "Test")
snapshot.appendItems([myItem])

dataSource.apply(snapshot) // <-- This works great, and as expected

// Now, let's apply another snapshot that includes an update to the item
let anotherSnapshot = DiffableDataSourceSnapshot<Int, MyItem>()
anotherSnapshot.appendSections([0])

let updatedItem = MyItem(id: 1, name: "Test 2") // <-- Notice that the id is the same, but the content is different
anotherSnapshot.appendItems([myItem])

dataSource.apply(anotherSnapshot) // <-- This results in 1 deletion, 1 insertion when it should produce 1 reload

Current Behavior

Item reloads are not discovered in complex items, because an equality check is used on the SnapshotStructure.Item differenceIdentifier instead of the hash value.

Steps to Reproduce

  1. Create an Xcode project using this library
  2. Take the small sample pasted above and put it in the project
  3. Run the project, and notice how items are deleted/inserted instead of reloaded

Cannot compile example macOS application

Checklist

  • This is not a Apple's bug.
  • Reviewed the README and documents.
  • Searched existing issues for ensure not duplicated.

Expected Behavior

We can compile example macOS application

Current Behavior

has compile error.

let snapshot = DiffableDataSourceSnapshot<Section, Mountain>()

this let should be var

Steps to Reproduce

  1. just run Example-macOS

Environments

  • version: 0.4.0

  • Swift version: 5.2.4

  • Xcode version: 11.6

Add subscript function for SectionIdentifierType

Checklist

  • Reviewed the README and documents.
  • Searched existing issues for ensure not duplicated.

Description

We want to have a getter function for the SectionIdentifierType, to be able to use different cell types depending on the section they are in.

Motivation and Context

We want to use IBPCollectionViewCompositionalLayout with different layouts per section. IBPCollectionViewCompositionalLayout refers to this datasource library. In the current implementation we were not able to achieve that because of the missing getter for the SectionIdentifierType.

Proposed Solution

Adding a subscript function for the SectionIdentifierType.

create a data source that vends multiple cell types?

Checklist

  • Reviewed the README and documents.
  • Searched existing issues for ensure not duplicated.

Expected Behavior

I'd like to use DiffableDataSources with different cell types.

Current Behavior

I'm able to create a single data source and single cell type and apply the changes. I'm obviously missing something because I cannot figure out how to create a data source that vends multiple object types. (I tried creating multiple data sources, but then ended up with the dreaded UICollectionView exceptions about attempt to delete item 2 from section 0 which only contains 2 items before the update.)

Detailed Description (Include Screenshots)

Here is how I'm creating "article" cells. I'm not sure how to create another cell type.

enum Section: Int, CaseIterable {
    case trends = 0
    case articles

    var cellIdentifier: String {
        switch self {
        case .trends:
            return "trendCell"
        case .articles:
            return "articleCell"
        }
    }
}

lazy var dataSource = CollectionViewDiffableDataSource<Section, Article> (collectionView: collectionView) { collectionView, indexPath, _ /*identifier*/ in
    if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: Section.articles.cellIdentifier, for: indexPath) as? ArticleCollectionViewCell {
        cell.article = self.articles[indexPath.item]
        return cell
    }

    fatalError()
}

var articles: [Article] = [] {
    didSet {

            let snapshot = DiffableDataSourceSnapshot<Section, Article>()
            snapshot.appendSections([.articles])
            snapshot.appendItems(articles, toSection: .articles)
            dataSource.apply(snapshot, animatingDifferences: true)
        }
    }
}

Environment

  • version: 0.1.0

  • Swift version: 5.0

  • iOS version: 12.2

  • Xcode version: 10.2.1

  • Devices/Simulators: iPhone X

  • CocoaPods/Carthage version: 0.33.0

Crash when custom UICollectionViewLayout

I create UICollectionView with custom UICollectionViewLayout
Call RestApi and update data with snapshot for CollectionViewDiffableDataSource
and result
var snapshot = DiffableDataSourceSnapshot<Section,Post>() let section = Section() snapshot.appendSections([section]) snapshot.appendItems(self.posts) self.dataSource.apply(snapshot)
If I use UICollectionViewDataSource (default) instead then no error
https://i.imgur.com/rl6FG9s.png

Environments

  • version:

  • Swift version: 5.1

  • iOS version: 12

  • Xcode version: 10.3

  • Devices/Simulators: iPhone X

  • CocoaPods/Carthage version:

Incorrect items applied on a collection view after data filtering

Checklist

  • This is not an Apple's bug. It works on the original implementation.
  • Reviewed the README and documents.
  • Searched existing issues for ensure not duplicated.

Expected Behavior

Applying two sets of trivial data to a collectionview, I expect the UI to match it in all cases - or at least understand which exceptional cases I should guard against and work them around as needed.

Current Behavior

Filtering a simple model array to a particular state makes the collection view fail to display them correctly, whereas the apple implementation does it.

Steps to Reproduce

  1. Create a snapshot from an array of Hashable models that combines the state from an array of model objects (simple id/title strings) and a isFavorite boolean value)
  2. Given a state0 (full list), filter it into state1 (filtered by some criteria)
  3. Filter it again into state1 (different, non-exclusive criteria)
  4. Toggle applying state1 and state2 to the table view. Going from state1 -> state2 yield different changesets every time you run it, most of the time resulting in wrong state

The collection view shows more items after snapshot from state2 being applied, than the actual array/snapshot has. The indexes get mixed up between what you tap and what is in the source array

Detailed Description (Include Screenshots)

I don't understand the cause exactly.

Reproducible Demo Project

https://github.com/rafaelnobrekz/DiffableBugRepro

Environments

  • version: 0.5.0 (DifferenceKit 1.2.0)

  • Swift version: 5.7

  • iOS version: iOS 16

  • Xcode version: Xcode 14

  • Devices/Simulators: iPhone 14 Pro Simulator (iOS 16), iPhone 12 Pro (iOS 16), iPhone 7 Plus (iOS13.7)

  • CocoaPods/Carthage version: n/a (SPM)

License missing copyright name, year

Checklist

  • Reviewed the README and documents.
  • Searched existing issues for ensure not duplicated.

Expected Behavior

The LICENSE file should contain the year of copyright and the name of the copyright holder.

Current Behavior

The LICENSE file only contains template variables:

Copyright [yyyy] [name of copyright owner]

I'm using Copyright 2019 ra1028 for now, but let me know if you'd prefer something else.

Thanks!

Create a table view section header or footer view?

Checklist

  • Reviewed the README and documents.
  • Searched existing issues for ensure not duplicated.

Expected Behavior

I'd like to show a header or footer view for a section of a table view.

Current Behavior

I'm able to use DiffableDataSources to create sections and add items to the section, and this generates cells, but I cannot figure out how to create a header or a footer view (e.g. a UITableViewHeaderFooterView) for a section of the table view.

For example , if I have:

enum Section {
  case .greetings
}

enum Row {
  case .hello
  case .goodbye
}

func buildSnapshot() {
  let snapshot = DiffableDataSourceSnapshot<Section, AnyHashable>()
  snapshot.appendSections([.greetings])
  snapshot.appendItems(Row.allCases, toSection: .greetings)
  return snapshot
}

lazy var dataSource = TableViewDiffableDataSource<Section, AnyHashable> (tableView: tableView) { tableView, indexPath, item in
  // this is only called for .hello and .goodbye
  // and i can only return a UITableViewCell - not a UITableViewHeaderFooterView
}

## Environment
- version: 0.1.0

- Swift version: 5.0.1

Applying a snapshot near the bottom of a table view jumps its scroll position

Checklist

  • This is not a Apple's bug.
  • Reviewed the README and documents.
  • Searched existing issues for ensure not duplicated.

Expected Behavior

On tableView didSelect delegate callback, I toggle the snapshot's Item isSelected property and apply a new snapshot with this data changed (otherwise selection would be lost when reusing cells, as the selection is set in my cell provider from the item)
When using the native UITableViewDiffableDataSource, the table view remains at the same content offset no matter where I apply the snapshot from.

Current Behavior

When using DiffableDataSource's TableViewDiffableDataSource, and the tableview's bottommost rows are visible, the scrolling position is offset after applying a snapshot

Reproducible Demo Project

https://github.com/rafaelnobrekz/DiffableDataSourceOffsetBug

Environments

  • version: 0.5

  • Swift version: 5.5

  • iOS version: 11-16

  • Xcode version: 14.2

  • Devices/Simulators:

  • CocoaPods/Carthage version:

How to use section index titles for UITableView? It is not showing up on the UI at all.

Checklist

  • Reviewed the README and documents.
  • Searched existing issues for ensure not duplicated.

Expected Behavior

Index section titles should show up.

Current Behavior

Index section titles are not showing up. I even inherited the TableViewDataSource<String,Int> and defined the section index title functions but they are not getting triggered.

Detailed Description (Include Screenshots)

Environment

  • version:
  • Swift version:
    Swift 5.0
  • iOS version:
    iOS 13.6
  • Xcode version:
    11.3.1
  • Devices/Simulators:
    Any
  • CocoaPods/Carthage version:
    1.9

Architecture issue

Could not find module 'DiffableDataSources' for target 'i386-apple-ios-simulator'; found: x86_64-apple-ios-simulator, x86_64

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.