All Projects → osteslag → Changeset

osteslag / Changeset

Licence: mit
Minimal edits from one collection to another

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Changeset

Persei
Animated top menu for UITableView / UICollectionView / UIScrollView written in Swift
Stars: ✭ 3,395 (+320.69%)
Mutual labels:  uicollectionview, uitableview
Flix
iOS reusable form library in Swift.
Stars: ✭ 725 (-10.16%)
Mutual labels:  uicollectionview, uitableview
Functionaltabledata
Declarative UITableViewDataSource implementation
Stars: ✭ 347 (-57%)
Mutual labels:  uicollectionview, uitableview
Gltablecollectionview
Netflix and App Store like UITableView with UICollectionView, written in pure Swift 4.2
Stars: ✭ 709 (-12.14%)
Mutual labels:  uicollectionview, uitableview
Emptydataset Swift
🎄 DZNEmptyDataSet implement with Swift.A drop-in UITableView/UICollectionView superclass category for showing empty datasets whenever the view has no content to display. DZNEmptyDataSet with Swift.
Stars: ✭ 443 (-45.11%)
Mutual labels:  uicollectionview, uitableview
Wlemptystate
WLEmptyState is an iOS based component that lets you customize the view when the dataset of a UITableView or a UICollectionView is empty. We created a sample project with the WLEmptyState component to show how you can use it.
Stars: ✭ 305 (-62.21%)
Mutual labels:  uicollectionview, uitableview
Bento
Swift library for building component-based interfaces on top of UITableView and UICollectionView 🍱
Stars: ✭ 371 (-54.03%)
Mutual labels:  diff, uitableview
MultiSelect
swift
Stars: ✭ 12 (-98.51%)
Mutual labels:  uitableview, uicollectionview
Mylinearlayout
MyLayout is a powerful iOS UI framework implemented by Objective-C. It integrates the functions with Android Layout,iOS AutoLayout,SizeClass, HTML CSS float and flexbox and bootstrap. So you can use LinearLayout,RelativeLayout,FrameLayout,TableLayout,FlowLayout,FloatLayout,PathLayout,GridLayout,LayoutSizeClass to build your App 自动布局 UIView UITab…
Stars: ✭ 4,152 (+414.5%)
Mutual labels:  uicollectionview, uitableview
Owl
A declarative type-safe framework for building fast and flexible lists with UITableViews & UICollectionViews
Stars: ✭ 423 (-47.58%)
Mutual labels:  uicollectionview, uitableview
Baraba
Make your UIScrollView scroll automatically when user is looking 👀 by tracking face using ARKit and AVFoundation
Stars: ✭ 268 (-66.79%)
Mutual labels:  uicollectionview, uitableview
Viewanimator
ViewAnimator brings your UI to life with just one line
Stars: ✭ 6,592 (+716.85%)
Mutual labels:  uicollectionview, uitableview
iOSEasyList
A data-driven UICollectionView and UITableView framework for building fast and flexible lists
Stars: ✭ 29 (-96.41%)
Mutual labels:  uitableview, uicollectionview
Livecollections
Automatically perform UITableView and UICollectionView animations between two sets of immutable data. It supports generic data types and is fully thread-safe.
Stars: ✭ 337 (-58.24%)
Mutual labels:  uicollectionview, uitableview
WBListKit
A data-driven UICollectionView&UITableView framework for building fast and flexible lists by declarative syntax.
Stars: ✭ 32 (-96.03%)
Mutual labels:  uitableview, uicollectionview
Uitableviewdynamiclayoutcacheheight
🖖高性能的自动计算采用 Autolayout 布局的 UITableViewCell 和 UITableViewHeaderFooterView 的高度,内部自动管理高度缓存。
Stars: ✭ 360 (-55.39%)
Mutual labels:  uicollectionview, uitableview
XLRefresh
iOS 下拉刷新工具
Stars: ✭ 25 (-96.9%)
Mutual labels:  uitableview, uicollectionview
CollectionAndTableViewCompatible
A set of Swift protocols and Xcode snippets that will make it easy to do clean UITableView code
Stars: ✭ 34 (-95.79%)
Mutual labels:  uitableview, uicollectionview
Lpdmvvmkit
LPDMvvmKit - Elegant MVVM framework in Objective-C.
Stars: ✭ 400 (-50.43%)
Mutual labels:  uicollectionview, uitableview
Datasources
💾 🔜📱 Type-safe data-driven CollectionView, TableView Framework. (We can also use ASCollectionNode)
Stars: ✭ 553 (-31.47%)
Mutual labels:  diff, uicollectionview

Changeset

Changeset – pretty awesome little project
Joel Levin

This is an attempt at implementing the solution outlined in Dave DeLong’s article, Edit distance and edit steps.

A Changeset describes the minimal edits required to go from one Collection of Equatable elements to another.

It has been written primarily to be used in conjunction with UITableView and UICollectionView data sources by detecting additions, deletions, substitutions, and moves between the two sets of data. But it can also be used to compute more general changes between two data sets.

Usage

The following code computes the minimal edits of the canonical example, going from the String collections “kitten” to “sitting”:

let changeset = Changeset(source: "kitten", target: "sitting")

print(changeset)
// 'kitten' -> 'sitting':
//     replace with s at offset 0
//     replace with i at offset 4
//     insert g at offset 6

The following assertion would then succeed:

let edits = [
    Changeset<String>.Edit(operation: .substitution, value: "s", destination: 0),
    Changeset<String>.Edit(operation: .substitution, value: "i", destination: 4),
    Changeset<String>.Edit(operation: .insertion, value: "g", destination: 6),
]
assert(changeset.edits == edits)

If you don’t want the overhead of Changeset itself, which also stores the source and target collections, you can call edits directly (here with example data from Apple’s Table View Programming Guide for iOS):

let source = ["Arizona", "California", "Delaware", "New Jersey", "Washington"]
let target = ["Alaska", "Arizona", "California", "Georgia", "New Jersey", "Virginia"]
let edits = Changeset.edits(from: source, to: target)

print(edits)
// [insert Alaska at offset 0, replace with Georgia at offset 2, replace with Virginia at offset 4]

Note that Changeset uses offsets, not indices, to refer to elements in the collections. This is mainly because Swift collections aren’t guaranteed to use zero-based integer indices. See discussion in issue #37 for more details.

UIKit Integration

The offset values can be used directly in the animation blocks of beginUpdates/endUpdates on UITableView and performBatchUpdates on UICollectionView in that Changeset follows the principles explained under Batch Insertion, Deletion, and Reloading of Rows and Sections in Apple’s guide.

In short; first all deletions and substitutions are made, relative to the source collection, then, relative to the resulting collection, insertions. A move is just a deletion followed by an insertion.

In the iOS framework, two convenience extensions (one on UITableView and one on UICollectionView) have been included to make animated table/collection view updates a breeze. Just call update, like this:

tableView.update(with: changeset.edits)

Custom Comparator

By default a Changeset uses == to compare elements, but you can write your own comparator, illustrated below, where the occurence of an “a” always triggers a change:

let alwaysChangeA: (Character, Character) -> Bool = {
    if $0 == "a" || $1 == "a" {
        return false
    } else {
        return $0 == $1
    }
}
let changeset = Changeset(source: "ab", target: "ab", comparator: alwaysChangeA)

As a result, the changeset will consist of a substitution of the “a” (to another “a”):

let expectedEdits: [Changeset<String>.Edit] = [Changeset.Edit(operation: .substitution, value: "a", destination: 0)]
assert(changeset.edits == expectedEdits)

One possible use of this is when a cell in a UITableView or UICollectionView shouldn’t animate when they change.

Test App

The Xcode project also contains a target to illustrate the usage in an app:

Test App

This uses the extensions mentioned above to animate transitions based on the edits of a Changeset.

License

This project is available under The MIT License.
Copyright © 2015-18, Joachim Bondo. See LICENSE file.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].