{"id":13490004,"url":"https://github.com/Adlai-Holler/ArrayDiff","last_synced_at":"2025-03-28T05:31:39.020Z","repository":{"id":56902385,"uuid":"43520449","full_name":"Adlai-Holler/ArrayDiff","owner":"Adlai-Holler","description":"A Swift utility to make updating table views/collection views trivially easy and reliable.","archived":false,"fork":false,"pushed_at":"2016-09-23T20:34:14.000Z","size":44,"stargazers_count":99,"open_issues_count":4,"forks_count":19,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-20T01:19:01.795Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Adlai-Holler.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-10-01T20:52:02.000Z","updated_at":"2024-09-08T20:14:06.000Z","dependencies_parsed_at":"2022-08-21T02:50:52.367Z","dependency_job_id":null,"html_url":"https://github.com/Adlai-Holler/ArrayDiff","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Adlai-Holler%2FArrayDiff","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Adlai-Holler%2FArrayDiff/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Adlai-Holler%2FArrayDiff/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Adlai-Holler%2FArrayDiff/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Adlai-Holler","download_url":"https://codeload.github.com/Adlai-Holler/ArrayDiff/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245978200,"owners_count":20703675,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T19:00:39.211Z","updated_at":"2025-03-28T05:31:38.695Z","avatar_url":"https://github.com/Adlai-Holler.png","language":"Swift","funding_links":[],"categories":["Libs"],"sub_categories":["Utility"],"readme":"# ArrayDiff [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) ![Pods](https://cocoapod-badges.herokuapp.com/v/ArrayDiff/badge.png) ![Pod platforms](https://cocoapod-badges.herokuapp.com/p/ArrayDiff/badge.png)\n\nAn efficient Swift utility to compute the difference between two arrays. Get the `removedIndexes` and `insertedIndexes` and pass them directly along to `UITableView` or `UICollectionView` when you update your data! The [diffing algorithm](https://en.wikipedia.org/wiki/Longest_common_subsequence_problem) is the same that powers the `diff` utility – it's robust and quick.\n\n## Basic Example\n\n```swift\nlet old = [ \"a\", \"b\", \"c\", \"d\" ]\nlet new = [ \"a\", \"c\", \"e\", \"f\", \"d\" ]\n\nlet diff = old.diff(new)\n// diff.removedIndexes = { 1 }\n// diff.insertedIndexes = { 2, 3 }\n\n// To update rows in section 0:\ntableView.beginUpdates()\nself.data = new\ndiff.applyToRowsInTableView(tableView, section: 0, rowAnimation: .Automatic)\ntableView.endUpdates()\n\n// Or to update sections:\ntableView.beginUpdates()\nself.data = new\ndiff.applyToSectionsInTableView(tableView, rowAnimation: .Automatic)\ntableView.endUpdates()\n```\n\n## Nested Diff\n\nYou can use types that conform to `SectionType` to perform nested row- and section-level diffs simultaneously:\n\n```swift\nlet old = [\n  BasicSection(name: \"Alpha\", items: [\"a\", \"b\", \"c\", \"d\", \"e\"]),\n  BasicSection(name: \"Bravo\", items: [\"f\", \"g\", \"h\", \"i\", \"j\"]),\n  BasicSection(name: \"Charlie\", items: [\"k\", \"l\", \"m\", \"n\", \"o\"])\n]\nlet new = [\n  BasicSection(name: \"Alpha\", items: [\"a\", \"b\", \"d\", \"e\", \"x\"]),\n  BasicSection(name: \"Charlie\", items: [\"f\", \"g\", \"h\", \"i\", \"j\"]),\n  BasicSection(name: \"Delta\", items: [\"f\", \"g\", \"h\", \"i\", \"j\"])\n]\n\nlet nestedDiff = old.diffNested(new)\n// nestedDiff.sectionsDiff.removedIndexes == {1}\n// nestedDiff.sectionsDiff.insertedIndexes == {2}\n// nestedDiff.itemDiffs[0].removedIndexes == {2}\n// nestedDiff.itemDiffs[0].insertedIndexes == {5}\n// etc.\n\ntableView.beginUpdates()\nself.data = new\nnestedDiff.applyToTableView(tableView, rowAnimation: .Automatic)\ntableView.endUpdates()\n```\n\n## Limitations\n\nItem moves are treated as remove/insert, so when they are animated the cell will \"teleport\" to its new position, rather than sliding there. If you would like this feature, let me know in the Issues!\n\n## Example Project\n\nCheck out the iOS app in the Example folder to see this framework pushed to its limits to drive a UITableView. In it we have a table view with 20 sections of strings. When you tap update, the data is randomly updated and we assert that the changes we made are equal to the changes that the framework recovers by comparing the two arrays.\n\n## Attribution\n\nThanks to https://github.com/khanlou/NSArray-LongestCommonSubsequence which I ~~took inspiration~~ totally copied from.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FAdlai-Holler%2FArrayDiff","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FAdlai-Holler%2FArrayDiff","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FAdlai-Holler%2FArrayDiff/lists"}