### Install DifferenceKit/UIKitExtension with CocoaPods Source: https://ra1028.github.io/DifferenceKit/index.html Install only the UIKit extensions for DifferenceKit. ```ruby pod 'DifferenceKit/UIKitExtension' ``` -------------------------------- ### Install DifferenceKit/Core with CocoaPods Source: https://ra1028.github.io/DifferenceKit/index.html Use this snippet to install only the core algorithm without UI extensions. ```ruby pod 'DifferenceKit/Core' ``` -------------------------------- ### Install DifferenceKit with Carthage Source: https://ra1028.github.io/DifferenceKit/index.html Add the DifferenceKit repository to your Cartfile for Carthage integration. ```ruby github "ra1028/DifferenceKit" ``` -------------------------------- ### Install DifferenceKit/AppKitExtension with CocoaPods for macOS Source: https://ra1028.github.io/DifferenceKit/index.html Install the AppKit extensions for DifferenceKit for macOS development. ```ruby pod 'DifferenceKit/AppKitExtension' ``` -------------------------------- ### Install DifferenceKit with CocoaPods for iOS/tvOS Source: https://ra1028.github.io/DifferenceKit/index.html Install the full DifferenceKit library including UIKit extensions for iOS and tvOS development. ```ruby pod 'DifferenceKit' ``` -------------------------------- ### StagedChangeset Start Index Source: https://ra1028.github.io/DifferenceKit/Structs/StagedChangeset.html Provides the starting index for iterating over the StagedChangeset. This is part of the Collection protocol conformance. ```swift public var startIndex: Int { get } ``` -------------------------------- ### ElementPath Initialization Source: https://ra1028.github.io/DifferenceKit/Structs/ElementPath.html Initializes a new ElementPath with specified element and section indices. ```APIDOC ## init(element:section:) ### Description Creates a new `ElementPath`. ### Method `init` ### Parameters #### Path Parameters - **element** (Int) - Required - The element index (or offset). - **section** (Int) - Required - The section index (or offset). ### Response #### Success Response - **ElementPath** - A newly created `ElementPath` instance. ``` -------------------------------- ### StagedChangeset Initialization with Source and Target Collections Source: https://ra1028.github.io/DifferenceKit/Structs/StagedChangeset.html Creates a StagedChangeset by calculating the differences between two linear collections. It uses an optimized diffing algorithm for high performance. ```APIDOC ## `init(source:target:)` (Linear Collections) ### Description Creates a new `StagedChangeset` from two linear collections. It calculates the differences using an algorithm optimized based on Paul Heckel’s diff algorithm. ### Note - This algorithm computes differences at high performance with O(n) complexity, but may not always calculate the shortest differences. - If elements with the same identifier are duplicated, the algorithm attempts to calculate moves and treats the rest as insertions or deletions. - The data and changes in each changeset represent the middle of the whole changes, with each change originating from the previous stage. ### Complexity O(n) ### Declaration Swift ```swift @inlinable init(source: Collection, target: Collection) ``` ### Parameters - `source` (Collection) - A source collection to calculate differences. - `target` (Collection) - A target collection to calculate differences. ``` -------------------------------- ### StagedChangeset Initialization with Source, Target, and Section Source: https://ra1028.github.io/DifferenceKit/Structs/StagedChangeset.html Creates a StagedChangeset by calculating the differences between two linear collections, specifying a section index for the changes. ```APIDOC ## `init(source:target:section:)` ### Description Creates a new `StagedChangeset` from two linear collections, specifying a section index. It calculates differences using an algorithm optimized based on Paul Heckel’s diff algorithm. ### Note - This algorithm computes differences at high performance with O(n) complexity, but may not always calculate the shortest differences. - If elements with the same identifier are duplicated, the algorithm attempts to calculate moves and treats the rest as insertions or deletions. - The data and changes in each changeset represent the middle of the whole changes, with each change originating from the previous stage. ### Complexity O(n) ### Declaration Swift ```swift @inlinable init(source: Collection, target: Collection, section: Int) ``` ### Parameters - `source` (Collection) - A source collection to calculate differences. - `target` (Collection) - A target collection to calculate differences. - `section` (Int) - An Int value to use as the section index (or offset) of the element. ``` -------------------------------- ### ArraySection Initializer with Source and Elements Source: https://ra1028.github.io/DifferenceKit/Structs/ArraySection.html Creates a new ArraySection by reproducing a source section and replacing its elements with a new collection. The element type of the collection must match the Element type of the ArraySection. ```swift @inlinable public init(source: ArraySection, elements: C) where Element == C.Element, C : Collection ``` -------------------------------- ### Changeset Initialization Source: https://ra1028.github.io/DifferenceKit/Structs/Changeset.html Initializes a new Changeset with specified collection data and changes to sections and elements. ```APIDOC ## Changeset.init ### Description Creates a new `Changeset`. ### Method `init(data:sectionDeleted:sectionInserted:sectionUpdated:sectionMoved:elementDeleted:elementInserted:elementUpdated:elementMoved:)` ### Parameters #### Parameters - **data** (Collection) - The collection after changed. - **sectionDeleted** ([Int]) - The offsets of deleted sections. Defaults to `[]`. - **sectionInserted** ([Int]) - The offsets of inserted sections. Defaults to `[]`. - **sectionUpdated** ([Int]) - The offsets of updated sections. Defaults to `[]`. - **sectionMoved** ([(source: Int, target: Int)]) - The pairs of source and target offset of moved sections. Defaults to `[]`. - **elementDeleted** ([ElementPath]) - The paths of deleted elements. Defaults to `[]`. - **elementInserted** ([ElementPath]) - The paths of inserted elements. Defaults to `[]`. - **elementUpdated** ([ElementPath]) - The paths of updated elements. Defaults to `[]`. - **elementMoved** ([(source: ElementPath, target: ElementPath)]) - The pairs of source and target path of moved elements. Defaults to `[]`. ``` -------------------------------- ### Simple Differentiable Conformance for String Source: https://ra1028.github.io/DifferenceKit/index.html Extend String to conform to Differentiable using its default Hashable conformance for simple diffing. ```swift extension String: Differentiable {} ``` -------------------------------- ### ElementPath Initializer Source: https://ra1028.github.io/DifferenceKit/Structs/ElementPath.html Initializes a new ElementPath with the specified element and section indices. Use this to create a path to a specific item in a nested structure. ```swift @inlinable public init(element: Int, section: Int) ``` -------------------------------- ### Add DifferenceKit Swift Package Manager for Apple platforms Source: https://ra1028.github.io/DifferenceKit/index.html Instructions for adding DifferenceKit as a Swift Package dependency using Xcode's GUI. ```text Repository: https://github.com/ra1028/DifferenceKit ``` -------------------------------- ### Changeset Initializer Source: https://ra1028.github.io/DifferenceKit/Structs/Changeset.html Creates a new Changeset instance with optional initial values for data and various change types. ```swift @inlinable public init( data: Collection, sectionDeleted: [Int] = [], sectionInserted: [Int] = [], sectionUpdated: [Int] = [], sectionMoved: [(source: Int, target: Int)] = [], elementDeleted: [ElementPath] = [], elementInserted: [ElementPath] = [], elementUpdated: [ElementPath] = [], elementMoved: [(source: ElementPath, target: ElementPath)] = [] ) ``` -------------------------------- ### init(arrayLiteral:) Source: https://ra1028.github.io/DifferenceKit/Structs/StagedChangeset.html Initializes a new StagedChangeset with an array literal of Changeset objects. This allows for convenient creation of a StagedChangeset using Swift's array literal syntax. ```APIDOC ## init(arrayLiteral:) ### Description Initializes a new StagedChangeset with an array literal of Changeset objects. This allows for convenient creation of a StagedChangeset using Swift's array literal syntax. ### Method `init` ### Parameters - **elements** (Changeset...): A variadic list of Changeset objects to initialize the StagedChangeset with. ### Declaration ```swift @inlinable public init(arrayLiteral elements: Changeset...) ``` ``` -------------------------------- ### ArraySection Initialization Source: https://ra1028.github.io/DifferenceKit/Structs/ArraySection.html Initializes an ArraySection with a model and a collection of elements. The elements in the collection must conform to the Element type of the ArraySection. ```APIDOC ## init(model:elements:) ### Description Creates a section with the model and the elements. ### Parameters - **model** (Model) - Required - A differentiable model of section. - **elements** (C) - Required - The collection of element in the section. ``` ```APIDOC ## init(source:elements:) ### Description Creates a new section reproducing the given source section with replacing the elements. ### Parameters - **source** (ArraySection) - Required - A source section to reproduce. - **elements** (C) - Required - The collection of elements for the new section. ``` -------------------------------- ### ArraySection Initializer with Model and Elements Source: https://ra1028.github.io/DifferenceKit/Structs/ArraySection.html Initializes an ArraySection with a specified model and a collection of elements. The element type of the collection must match the Element type of the ArraySection. ```swift @inlinable public init(model: Model, elements: C) where Element == C.Element, C : Collection ``` -------------------------------- ### Initialize StagedChangeset with Changesets Source: https://ra1028.github.io/DifferenceKit/Structs/StagedChangeset.html Creates a new StagedChangeset from a collection of existing Changesets. This is useful when you have pre-computed changesets. ```swift public init(_ changesets: C) where C : Collection, C.Element == Changeset ``` -------------------------------- ### StagedChangeset Initialization Source: https://ra1028.github.io/DifferenceKit/Structs/StagedChangeset.html Initializes a StagedChangeset with a collection of Changesets. This is useful when you have pre-computed changesets that you want to group together. ```APIDOC ## `init(_:)` ### Description Creates a new `StagedChangeset`. ### Declaration Swift ```swift @inlinable public init(_ changesets: C) where C : Collection, C.Element == Changeset ``` ### Parameters - `_changesets_` (Collection of Changeset) - The collection of `Changeset`. ``` -------------------------------- ### Using AnyDifferentiable for Mixed-Type Collections Source: https://ra1028.github.io/DifferenceKit/Structs/AnyDifferentiable.html Demonstrates how to use AnyDifferentiable to store and compare mixed-type elements in a collection. This is useful when a collection requires Differentiable conformance but needs to hold elements of different types. ```swift extension String: Differentiable {} extension Int: Differentiable {} let source = [ AnyDifferentiable("ABC"), AnyDifferentiable(100) ] let target = [ AnyDifferentiable("ABC"), AnyDifferentiable(100), AnyDifferentiable(200) ] let changeset = StagedChangeset(source: source, target: target) print(changeset.isEmpty) // prints "false" ``` -------------------------------- ### Initialize StagedChangeset for Linear Collections Source: https://ra1028.github.io/DifferenceKit/Structs/StagedChangeset.html Creates a new StagedChangeset by calculating differences between two linear collections. This initializer uses an optimized diff algorithm with O(n) complexity. ```swift init(source: Collection, target: Collection) ``` -------------------------------- ### Equality Comparison Source: https://ra1028.github.io/DifferenceKit/Structs/Changeset.html Compares two Changeset instances for equality. ```APIDOC ## Changeset Equality ### Description Compares two `Changeset` instances for equality. Since offsets are unordered, order is ignored when comparing two `Changeset`s. ### Method `==(_:_:)` ### Parameters - **lhs** (Changeset) - The left-hand side Changeset. - **rhs** (Changeset) - The right-hand side Changeset. ### Returns `Bool` - `true` if the Changesets are equal, `false` otherwise. ``` -------------------------------- ### Initialize StagedChangeset for Linear Collections with Section Source: https://ra1028.github.io/DifferenceKit/Structs/StagedChangeset.html Creates a new StagedChangeset for linear collections, specifying a section index for the elements. It uses an optimized diff algorithm with O(n) complexity. ```swift init(source: Collection, target: Collection, section: Int) ``` -------------------------------- ### ElementPath Debug Description Source: https://ra1028.github.io/DifferenceKit/Structs/ElementPath.html Provides a string representation of the ElementPath for debugging purposes. ```swift public var debugDescription: String { get } ``` -------------------------------- ### Default Initializer for StagedChangeset Source: https://ra1028.github.io/DifferenceKit/Structs/StagedChangeset.html Initializes an empty StagedChangeset. This can be used to create an empty state before populating it with changes. ```swift public init() ``` -------------------------------- ### Calculating StagedChangeset for Simple Collections Source: https://ra1028.github.io/DifferenceKit/index.html Create a StagedChangeset from two collections of Differentiable elements to calculate differences. ```swift let source = [ User(id: 0, name: "Vincent"), User(id: 1, name: "Jules") ] let target = [ User(id: 1, name: "Jules"), User(id: 0, name: "Vincent"), User(id: 2, name: "Butch") ] let changeset = StagedChangeset(source: source, target: target) ``` -------------------------------- ### debugDescription Source: https://ra1028.github.io/DifferenceKit/Structs/StagedChangeset.html Provides a string representation of the StagedChangeset for debugging purposes. This property is read-only. ```APIDOC ## debugDescription ### Description Provides a string representation of the StagedChangeset for debugging purposes. This property is read-only. ### Property `var` ### Declaration ```swift public var debugDescription: String { get } ``` ``` -------------------------------- ### isContentEqual(to:) Source: https://ra1028.github.io/DifferenceKit/Extensions/Optional.html Compares the content of an Optional value with another Optional value. It returns true if both are nil, and false if one is nil and the other is not. The comparison of the wrapped values is delegated to the Wrapped type's `isContentEqual(to:)` method. ```APIDOC ## isContentEqual(to:) ### Description Indicate whether the content of `self` is equals to the content of the given source value. Returns `true` if both values compared are nil. The result of comparison between nil and non-nil values is `false`. ### Method `isContentEqual(to:) ### Parameters #### Path Parameters - **source** (Wrapped?) - Required - An optional source value to be compared. ### Return Value A Boolean value indicating whether the content of `self` is equals to the given source value. ### Request Example ```swift let optionalInt1: Int? = 5 let optionalInt2: Int? = 5 let optionalInt3: Int? = nil optionalInt1.isContentEqual(to: optionalInt2) // true optionalInt1.isContentEqual(to: optionalInt3) // false optionalInt3.isContentEqual(to: nil) // true ``` ### Response #### Success Response (Bool) - **true**: if the contents are equal or both are nil. - **false**: if the contents are not equal or one is nil and the other is not. #### Response Example ```json true ``` ``` -------------------------------- ### StagedChangeset Initialization with Sectioned Collections Source: https://ra1028.github.io/DifferenceKit/Structs/StagedChangeset.html Creates a StagedChangeset by calculating the differences between two sectioned collections. This is useful for applying staged changes to UICollectionView. ```APIDOC ## `init(source:target:)` (Sectioned Collections) ### Description Creates a new `StagedChangeset` from two sectioned collections. It calculates the differences using an algorithm optimized based on Paul Heckel’s diff algorithm. ### Note - This algorithm computes differences at high performance with O(n) complexity, but may not always calculate the shortest differences. - If elements with the same identifier are duplicated, the algorithm attempts to calculate moves and treats the rest as insertions or deletions. - The data and changes in each changeset represent the middle of the whole changes, with each change originating from the previous stage. ### Complexity O(n) ### Declaration Swift ```swift @inlinable init(source: Collection, target: Collection) ``` ### Parameters - `source` (Collection) - A source sectioned collection to calculate differences. - `target` (Collection) - A target sectioned collection to calculate differences. ``` -------------------------------- ### Add DifferenceKit Swift Package Manager dependency Source: https://ra1028.github.io/DifferenceKit/index.html Add the DifferenceKit Git repository to your Package.swift file's dependencies. ```swift .package(url: "https://github.com/ra1028/DifferenceKit.git", from: "version") ``` -------------------------------- ### StagedChangeset Initialization with Array Literal Source: https://ra1028.github.io/DifferenceKit/Structs/StagedChangeset.html Initializes a StagedChangeset instance using an array literal of Changeset elements. ```swift @inlinable public init(arrayLiteral elements: Changeset...) ``` -------------------------------- ### AnyDifferentiable Initialization Source: https://ra1028.github.io/DifferenceKit/Structs/AnyDifferentiable.html Creates a type-erased differentiable value that wraps the given instance. This allows you to store different types of Differentiable values in a single collection. ```APIDOC ## init(_:) ### Description Creates a type-erased differentiable value that wraps the given instance. ### Method `init(_ base: D) where D : Differentiable` ### Parameters #### Parameters - **_base_** (Differentiable) - A differentiable value to wrap. ``` -------------------------------- ### reload(using:deleteSectionsAnimation:insertSectionsAnimation:reloadSectionsAnimation:deleteRowsAnimation:insertRowsAnimation:reloadRowsAnimation:interrupt:setData:) Source: https://ra1028.github.io/DifferenceKit/Extensions/UITableView.html Applies multiple animated updates in stages using `StagedChangeset` with specific animations for sections and rows. Similar to the other `reload` method, it aims to prevent crashes from simultaneous batch updates and requires synchronous data source updates. ```APIDOC ## reload(using:deleteSectionsAnimation:insertSectionsAnimation:reloadSectionsAnimation:deleteRowsAnimation:insertRowsAnimation:reloadRowsAnimation:interrupt:setData:) ### Description Applies multiple animated updates in stages using `StagedChangeset` with specific animations for sections and rows. Similar to the other `reload` method, it aims to prevent crashes from simultaneous batch updates and requires synchronous data source updates. ### Method Swift ### Endpoint N/A (Extension Method) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Parameters - **stagedChangeset** (StagedChangeset) - A staged set of changes. - **deleteSectionsAnimation** (@autoclosure () -> RowAnimation) - An option to animate the section deletion. - **insertSectionsAnimation** (@autoclosure () -> RowAnimation) - An option to animate the section insertion. - **reloadSectionsAnimation** (@autoclosure () -> RowAnimation) - An option to animate the section reload. - **deleteRowsAnimation** (@autoclosure () -> RowAnimation) - An option to animate the row deletion. - **insertRowsAnimation** (@autoclosure () -> RowAnimation) - An option to animate the row insertion. - **reloadRowsAnimation** (@autoclosure () -> RowAnimation) - An option to animate the row reload. - **interrupt** ((Changeset) -> Bool)? - A closure that takes an changeset as its argument and returns `true` if the animated updates should be stopped and performed reloadData. Default is nil. - **setData** ((C) -> Void) - A closure that takes the collection as a parameter. The collection should be set to data-source of UITableView. ### Request Example N/A ### Response #### Success Response (200) N/A #### Response Example N/A ``` -------------------------------- ### reload(using:with:interrupt:setData:) Source: https://ra1028.github.io/DifferenceKit/Extensions/UITableView.html Applies multiple animated updates in stages using `StagedChangeset`. This method is designed to avoid crashes that can occur when applying certain combinations of changes simultaneously in `performBatchUpdates`. It requires the data source to be updated synchronously before each stage of `performBatchUpdates`. ```APIDOC ## reload(using:with:interrupt:setData:) ### Description Applies multiple animated updates in stages using `StagedChangeset`. This method is designed to avoid crashes that can occur when applying certain combinations of changes simultaneously in `performBatchUpdates`. It requires the data source to be updated synchronously before each stage of `performBatchUpdates`. ### Method Swift ### Endpoint N/A (Extension Method) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Parameters - **stagedChangeset** (StagedChangeset) - A staged set of changes. - **animation** (@autoclosure () -> RowAnimation) - An option to animate the updates. - **interrupt** ((Changeset) -> Bool)? - A closure that takes an changeset as its argument and returns `true` if the animated updates should be stopped and performed reloadData. Default is nil. - **setData** ((C) -> Void) - A closure that takes the collection as a parameter. The collection should be set to data-source of UITableView. ### Request Example N/A ### Response #### Success Response (200) N/A #### Response Example N/A ``` -------------------------------- ### Changeset Equality Operator Source: https://ra1028.github.io/DifferenceKit/Structs/Changeset.html Compares two Changeset instances for equality. ```swift public static func == (lhs: Changeset, rhs: Changeset) -> Bool ``` -------------------------------- ### Changeset Data Property Source: https://ra1028.github.io/DifferenceKit/Structs/Changeset.html Represents the collection after changes have been applied. ```swift public var data: Collection ``` -------------------------------- ### StagedChangeset Index After Source: https://ra1028.github.io/DifferenceKit/Structs/StagedChangeset.html Returns the index after the given index, used for collection iteration. Conforms to the Collection protocol. ```swift public func index(after i: Int) -> Int ``` -------------------------------- ### ContentEquatable Protocol Declaration Source: https://ra1028.github.io/DifferenceKit/Protocols/ContentEquatable.html Defines the ContentEquatable protocol, which requires conformance to Equatable and provides a default implementation for content comparison. ```swift public protocol ContentEquatable ``` -------------------------------- ### UITableView Extension Declaration Source: https://ra1028.github.io/DifferenceKit/UI%20Extensions.html Shows the public extension declaration for UITableView in Swift. ```swift public extension UITableView ``` -------------------------------- ### ArraySection Content Comparison Source: https://ra1028.github.io/DifferenceKit/Structs/ArraySection.html Indicates whether the content of the current ArraySection is equal to the content of a given source section. The comparison is based on the models of the sections. ```APIDOC ## isContentEqual(to:) ### Description Indicate whether the content of `self` is equals to the content of the given source section. Note It’s compared by the model of `self` and the specified section. ### Parameters - **source** (ArraySection) - Required - A source section to compare. ### Return Value A Boolean value indicating whether the content of `self` is equals to the given source section. ``` -------------------------------- ### reload(using:interrupt:setData:) Source: https://ra1028.github.io/DifferenceKit/Extensions/UICollectionView.html Applies multiple animated updates in stages using `StagedChangeset`. This method is designed to handle complex updates by breaking them down into manageable stages, avoiding potential crashes associated with simultaneous batch updates. It requires the data source to be updated synchronously before each stage of `performBatchUpdates`. ```APIDOC ## reload(using:interrupt:setData:) ### Description Applies multiple animated updates in stages using `StagedChangeset`. This method is designed to handle complex updates by breaking them down into manageable stages, avoiding potential crashes associated with simultaneous batch updates. It requires the data source to be updated synchronously before each stage of `performBatchUpdates`. ### Method `func` ### Parameters - `stagedChangeset` (StagedChangeset) - Required - A staged set of changes. - `interrupt` ((Changeset) -> Bool)? - Optional - A closure that takes an changeset as its argument and returns `true` if the animated updates should be stopped and performed reloadData. Default is nil. - `setData` (C) -> Void - Required - A closure that takes the collection as a parameter. The collection should be set to data-source of UICollectionView. ``` -------------------------------- ### Reload UITableView with Staged Changeset and Default Animations Source: https://ra1028.github.io/DifferenceKit/Extensions/UITableView.html Applies multiple animated updates in stages using `StagedChangeset`. Ensure the data-source is updated synchronously before `performBatchUpdates` in every stage. Avoids crashes by assuming `StagedChangeset` has minimum staged changesets. ```swift func reload( using stagedChangeset: StagedChangeset, with animation: @autoclosure () -> RowAnimation, interrupt: ((Changeset) -> Bool)? = nil, setData: (C) -> Void ) ``` -------------------------------- ### isContentEqual Method for Optional Source: https://ra1028.github.io/DifferenceKit/Extensions/Optional.html Compares the content of an optional value with another optional value. Returns true if both are nil, and false if one is nil and the other is not. The comparison relies on the wrapped type's conformance to ContentEquatable if both values are non-nil. ```swift @inlinable public func isContentEqual(to source: Wrapped?) -> Bool ``` -------------------------------- ### Changeset Section Moved Property Source: https://ra1028.github.io/DifferenceKit/Structs/Changeset.html Stores pairs of source and target offsets for moved sections. ```swift public var sectionMoved: [(source: Int, target: Int)] ``` -------------------------------- ### differenceIdentifier Default Implementation Source: https://ra1028.github.io/DifferenceKit/Protocols/Differentiable.html Provides a default implementation for differenceIdentifier, using self as the identifier. ```swift var differenceIdentifier: DifferenceIdentifier { get } ``` -------------------------------- ### ArraySection isContentEqual Method Source: https://ra1028.github.io/DifferenceKit/Structs/ArraySection.html Indicates whether the content of the current ArraySection is equal to the content of another specified ArraySection. Comparison is based on the models of the two sections. ```swift @inlinable public func isContentEqual(to source: ArraySection) -> Bool ``` -------------------------------- ### == Source: https://ra1028.github.io/DifferenceKit/Structs/StagedChangeset.html Compares two StagedChangeset instances for equality. Returns true if both changesets contain the same sequence of changes. ```APIDOC ## == ### Description Compares two StagedChangeset instances for equality. Returns true if both changesets contain the same sequence of changes. ### Method `static func` ### Parameters - **lhs** (StagedChangeset): The left-hand side StagedChangeset. - **rhs** (StagedChangeset): The right-hand side StagedChangeset. ### Declaration ```swift @inlinable public static func == (lhs: StagedChangeset, rhs: StagedChangeset) -> Bool ``` ``` -------------------------------- ### Using AnyDifferentiable for Mixed Collections Source: https://ra1028.github.io/DifferenceKit/index.html Wrap elements of mixed types conforming to Differentiable using AnyDifferentiable to include them in a single collection for diffing. ```swift let source = [ AnyDifferentiable("A"), AnyDifferentiable(User(id: 0, name: "Vincent")) ] ``` -------------------------------- ### Changeset Element Moved Property Source: https://ra1028.github.io/DifferenceKit/Structs/Changeset.html Stores pairs of source and target paths for moved elements. ```swift public var elementMoved: [(source: ElementPath, target: ElementPath)] ``` -------------------------------- ### AnyDifferentiable.isContentEqual(to:) Source: https://ra1028.github.io/DifferenceKit/Structs/AnyDifferentiable.html Indicates whether the content of the wrapped value is equal to the content of another AnyDifferentiable instance. ```APIDOC ## isContentEqual(to:) ### Description Indicate whether the content of `base` is equals to the content of the given source value. ### Method `func isContentEqual(to source: AnyDifferentiable) -> Bool` ### Parameters #### Parameters - **source** (AnyDifferentiable) - A source value to be compared. ### Return Value A Boolean value indicating whether the content of `base` is equals to the content of `base` of the given source value. ``` -------------------------------- ### Changeset Properties Source: https://ra1028.github.io/DifferenceKit/Structs/Changeset.html Provides access to the data and various change counts and flags within a Changeset. ```APIDOC ## Changeset Properties ### Description Accesses the collection data and counts of various changes within the `Changeset`. ### Properties - **data** (Collection) - The collection after changed. - **sectionDeleted** ([Int]) - The offsets of deleted sections. - **sectionInserted** ([Int]) - The offsets of inserted sections. - **sectionUpdated** ([Int]) - The offsets of updated sections. - **sectionMoved** ([(source: Int, target: Int)]) - The pairs of source and target offset of moved sections. - **elementDeleted** ([ElementPath]) - The paths of deleted elements. - **elementInserted** ([ElementPath]) - The paths of inserted elements. - **elementUpdated** ([ElementPath]) - The paths of updated elements. - **elementMoved** ([(source: ElementPath, target: ElementPath)]) - The pairs of source and target path of moved elements. - **sectionChangeCount** (Int) - The number of section changes. - **elementChangeCount** (Int) - The number of element changes. - **changeCount** (Int) - The number of all changes. - **hasSectionChanges** (Bool) - A Boolean value indicating whether there are section changes. - **hasElementChanges** (Bool) - A Boolean value indicating whether there are element changes. - **hasChanges** (Bool) - A Boolean value indicating whether there are any changes. - **debugDescription** (String) - The debug description of the Changeset. ``` -------------------------------- ### Default Differentiable Conformance for Hashable Types Source: https://ra1028.github.io/DifferenceKit/index.html Leverage default implementations for types conforming to Hashable. The type itself is used as the identifier. ```swift // If `Self` conforming to `Hashable`. var differenceIdentifier: Self { return self } ``` -------------------------------- ### Initializer Declaration for DifferentiableSection Source: https://ra1028.github.io/DifferenceKit/Protocols/DifferentiableSection.html Declares the initializer for DifferentiableSection. It takes a source section and a new collection of elements to create a reproduced section. ```swift init(source: Self, elements: C) where C : Collection, C.Element == Self.Collection.Element ``` -------------------------------- ### Changeset Has Section Changes Source: https://ra1028.github.io/DifferenceKit/Structs/Changeset.html A boolean indicating if any section-related changes are present. ```swift @inlinable var hasSectionChanges: Bool { get } ``` -------------------------------- ### Reload UITableView with Staged Changeset and Specific Animations Source: https://ra1028.github.io/DifferenceKit/Extensions/UITableView.html Applies multiple animated updates in stages using `StagedChangeset` with explicit animation options for sections and rows. Ensure the data-source is updated synchronously before `performBatchUpdates` in every stage. Avoids crashes by assuming `StagedChangeset` has minimum staged changesets. ```swift func reload( using stagedChangeset: StagedChangeset, deleteSectionsAnimation: @autoclosure () -> RowAnimation, insertSectionsAnimation: @autoclosure () -> RowAnimation, reloadSectionsAnimation: @autoclosure () -> RowAnimation, deleteRowsAnimation: @autoclosure () -> RowAnimation, insertRowsAnimation: @autoclosure () -> RowAnimation, reloadRowsAnimation: @autoclosure () -> RowAnimation, interrupt: ((Changeset) -> Bool)? = nil, setData: (C) -> Void ) ``` -------------------------------- ### Performing Batch Updates on UITableView Source: https://ra1028.github.io/DifferenceKit/index.html Apply calculated changesets to a UITableView using the `reload` method. Ensure data source is updated synchronously within the completion closure. ```swift tableView.reload(using: changeset, with: .fade) { data in dataSource.data = data } ``` -------------------------------- ### Default Differentiable Conformance for Equatable Types Source: https://ra1028.github.io/DifferenceKit/index.html Leverage default implementations for types conforming to Equatable. Content equality is determined by the equality operator. ```swift // If `Self` conforming to `Equatable`. func isContentEqual(to source: Self) -> Bool { return self == source } ``` -------------------------------- ### StagedChangeset Equality Comparison Source: https://ra1028.github.io/DifferenceKit/Structs/StagedChangeset.html Implements the equality comparison operator for StagedChangeset instances. ```swift @inlinable public static func == (lhs: StagedChangeset, rhs: StagedChangeset) -> Bool ``` -------------------------------- ### UICollectionView Extension Declaration Source: https://ra1028.github.io/DifferenceKit/UI%20Extensions.html Shows the public extension declaration for UICollectionView in Swift. ```swift public extension UICollectionView ``` -------------------------------- ### Element Index Property Source: https://ra1028.github.io/DifferenceKit/Structs/ElementPath.html The 'element' property stores the index or offset of the element within its collection. ```swift public var element: Int ``` -------------------------------- ### StagedChangeset End Index Source: https://ra1028.github.io/DifferenceKit/Structs/StagedChangeset.html Provides the ending index for iterating over the StagedChangeset. This is part of the Collection protocol conformance. ```swift public var endIndex: Int { get } ``` -------------------------------- ### Changeset Element Updated Property Source: https://ra1028.github.io/DifferenceKit/Structs/Changeset.html Stores the paths of elements that have been updated. ```swift public var elementUpdated: [ElementPath] ``` -------------------------------- ### Section Index Property Source: https://ra1028.github.io/DifferenceKit/Structs/ElementPath.html The 'section' property stores the index or offset of the section containing the element. ```swift public var section: Int ``` -------------------------------- ### Changeset Element Inserted Property Source: https://ra1028.github.io/DifferenceKit/Structs/Changeset.html Stores the paths of elements that have been inserted. ```swift public var elementInserted: [ElementPath] ``` -------------------------------- ### isContentEqual Function Signature Source: https://ra1028.github.io/DifferenceKit/Protocols/ContentEquatable.html Declares the isContentEqual function, which is used to compare the content of two values. It relies on the == operator for comparison. ```swift func isContentEqual(to source: Self) -> Bool ``` -------------------------------- ### Changeset Has Changes Source: https://ra1028.github.io/DifferenceKit/Structs/Changeset.html A boolean indicating if any changes (section or element) are present. ```swift @inlinable var hasChanges: Bool { get } ``` -------------------------------- ### User Struct Conforming to Differentiable Source: https://ra1028.github.io/DifferenceKit/index.html Define a custom struct that conforms to the Differentiable protocol. Implement `differenceIdentifier` for unique identification and `isContentEqual` for content comparison. ```swift struct User: Differentiable { let id: Int let name: String var differenceIdentifier: Int { return id } func isContentEqual(to source: User) -> Bool { return name == source.name } } ``` -------------------------------- ### Calculate Differences Between Sectioned Collections Source: https://ra1028.github.io/DifferenceKit/Structs/StagedChangeset.html Use this snippet to calculate differences between two sectioned collections. The elements within each section are compared. ```swift let source = [ Section(model: "A", elements: ["😉"]) ] let target = [ Section(model: "A", elements: ["😉, 😺"]), Section(model: "B", elements: ["😪"]) ] let changeset = StagedChangeset(source: sectionedSource, target: sectionedTarget) print(changeset.isEmpty) // prints "false" ``` -------------------------------- ### Changeset Section Deleted Property Source: https://ra1028.github.io/DifferenceKit/Structs/Changeset.html Stores the offsets of sections that have been deleted. ```swift public var sectionDeleted: [Int] ``` -------------------------------- ### Changeset Element Deleted Property Source: https://ra1028.github.io/DifferenceKit/Structs/Changeset.html Stores the paths of elements that have been deleted. ```swift public var elementDeleted: [ElementPath] ``` -------------------------------- ### Changeset Section Updated Property Source: https://ra1028.github.io/DifferenceKit/Structs/Changeset.html Stores the offsets of sections that have been updated. ```swift public var sectionUpdated: [Int] ``` -------------------------------- ### Calculating StagedChangeset for Sectioned Collections Source: https://ra1028.github.io/DifferenceKit/index.html Define sections conforming to DifferentiableSection, typically using ArraySection, to calculate diffs for sectioned collections. ```swift enum Model: Differentiable { case a, b, c } let source: [ArraySection] = [ ArraySection(model: .a, elements: ["A", "B"]), ArraySection(model: .b, elements: ["C"]) ] let target: [ArraySection] = [ ArraySection(model: .c, elements: ["D", "E"]), ArraySection(model: .a, elements: ["A"]), ArraySection(model: .b, elements: ["B", "C"]) ] let changeset = StagedChangeset(source: source, target: target) ``` -------------------------------- ### AnyDifferentiable Properties Source: https://ra1028.github.io/DifferenceKit/Structs/AnyDifferentiable.html Provides access to the wrapped base value and its type-erased identifier. ```APIDOC ## Properties ### base #### Description The value wrapped by this instance. #### Declaration `public var base: Any { get }` ### differenceIdentifier #### Description A type-erased identifier value for difference calculation. #### Declaration `public var differenceIdentifier: AnyHashable { get }` ``` -------------------------------- ### Changeset Has Element Changes Source: https://ra1028.github.io/DifferenceKit/Structs/Changeset.html A boolean indicating if any element-related changes are present. ```swift @inlinable var hasElementChanges: Bool { get } ``` -------------------------------- ### Optional Extension for ContentEquatable Source: https://ra1028.github.io/DifferenceKit/Extensions/Optional.html Extends the Optional type to conform to ContentEquatable when its wrapped type also conforms to ContentEquatable. This allows for content-based equality checks on optional values. ```swift @frozen extension Optional: ContentEquatable where Wrapped: ContentEquatable ``` -------------------------------- ### Swift Protocol Declaration: ContentEquatable Source: https://ra1028.github.io/DifferenceKit/Diffing.html Defines a protocol for values that can compare their content for equality. ```swift public protocol ContentEquatable ``` -------------------------------- ### Changeset Total Change Count Source: https://ra1028.github.io/DifferenceKit/Structs/Changeset.html Calculates the total number of all changes within the changeset. ```swift @inlinable var changeCount: Int { get } ``` -------------------------------- ### Changeset Section Inserted Property Source: https://ra1028.github.io/DifferenceKit/Structs/Changeset.html Stores the offsets of sections that have been inserted. ```swift public var sectionInserted: [Int] ``` -------------------------------- ### Changeset Section Change Count Source: https://ra1028.github.io/DifferenceKit/Structs/Changeset.html Calculates the total number of changes related to sections. ```swift @inlinable var sectionChangeCount: Int { get } ``` -------------------------------- ### Changeset Element Change Count Source: https://ra1028.github.io/DifferenceKit/Structs/Changeset.html Calculates the total number of changes related to elements. ```swift @inlinable var elementChangeCount: Int { get } ``` -------------------------------- ### ElementPath Struct Declaration Source: https://ra1028.github.io/DifferenceKit/Structs/ElementPath.html Declares the ElementPath struct, which represents a path to a specific element within a tree of nested collections. It is Hashable for performance benefits. ```swift public struct ElementPath : Hashable ``` -------------------------------- ### Reload UICollectionView with Staged Changesets Source: https://ra1028.github.io/DifferenceKit/Extensions/UICollectionView.html Use this method to apply multiple animated updates to a UICollectionView in stages using `StagedChangeset`. The data source must be updated synchronously before each stage. The `interrupt` parameter allows stopping updates and performing a reloadData. ```swift public extension UICollectionView * ` reload(using:interrupt:setData:) ` Applies multiple animated updates in stages using `StagedChangeset`. Note There are combination of changes that crash when applied simultaneously in `performBatchUpdates`. Assumes that `StagedChangeset` has a minimum staged changesets to avoid it. The data of the data-source needs to be updated synchronously before `performBatchUpdates` in every stages. #### Declaration Swift ``` func reload( using stagedChangeset: StagedChangeset, interrupt: ((Changeset) -> Bool)? = nil, setData: (C) -> Void ) ``` #### Parameters ` _stagedChangeset_ ` | A staged set of changes. ---|--- ` _interrupt_ ` | A closure that takes an changeset as its argument and returns `true` if the animated updates should be stopped and performed reloadData. Default is nil. ` _setData_ ` | A closure that takes the collection as a parameter. The collection should be set to data-source of UICollectionView. ``` -------------------------------- ### StagedChangeset Subscript Access Source: https://ra1028.github.io/DifferenceKit/Structs/StagedChangeset.html Allows accessing individual Changesets within the StagedChangeset by their index. Conforms to the Collection protocol. ```swift public subscript(position: Int) -> Changeset { get set } ``` -------------------------------- ### Differentiable Protocol Declaration Source: https://ra1028.github.io/DifferenceKit/Protocols/Differentiable.html Defines the Differentiable protocol, which must conform to ContentEquatable. ```swift public protocol Differentiable : ContentEquatable ``` -------------------------------- ### Calculate Differences Between Two Linear Collections Source: https://ra1028.github.io/DifferenceKit/Changeset.html Use StagedChangeset to calculate the differences between two linear collections. This is useful for identifying staged changes that can be applied without conflicts. ```swift extension String: Differentiable {} let source = ["A", "B", "C"] let target = ["B", "C", "D"] let changeset = StagedChangeset(source: source, target: target) print(changeset.isEmpty) // prints "false" ``` -------------------------------- ### ArraySection Model Property Source: https://ra1028.github.io/DifferenceKit/Structs/ArraySection.html The model property of an ArraySection, used for differentiating the section from others. ```swift public var model: Model ``` -------------------------------- ### Changeset Declaration Source: https://ra1028.github.io/DifferenceKit/Changeset.html The declaration for the Changeset struct, representing a set of changes in a sectioned collection. Changes to the section of a linear collection should be empty. ```swift public struct Changeset where Collection : Collection ``` -------------------------------- ### DifferenceIdentifier Associated Type Source: https://ra1028.github.io/DifferenceKit/Protocols/Differentiable.html Specifies the associated type for the identifier, which must conform to Hashable. ```swift associatedtype DifferenceIdentifier : Hashable ``` -------------------------------- ### StagedChangeset Declaration Source: https://ra1028.github.io/DifferenceKit/Changeset.html The declaration for the StagedChangeset struct, which represents an ordered collection of Changesets. ```swift public struct StagedChangeset where Collection : Collection ``` -------------------------------- ### ArraySection Elements Property Source: https://ra1028.github.io/DifferenceKit/Structs/ArraySection.html The elements property of an ArraySection, holding the array of elements within the section. ```swift public var elements: [Element] ``` -------------------------------- ### Interrupting Batch Updates for Large Changesets Source: https://ra1028.github.io/DifferenceKit/index.html Conditionally fall back to `reloadData` for large changesets by returning true from the `interrupt` closure to prevent performance issues. ```swift collectionView.reload(using: changeset, interrupt: { $0.changeCount > 100 }) { data in dataSource.data = data } ``` -------------------------------- ### DifferentiableSection Protocol Declaration Source: https://ra1028.github.io/DifferenceKit/Protocols/DifferentiableSection.html Defines the DifferentiableSection protocol, which requires an associated 'Collection' type that must conform to the Collection protocol and whose elements must be Differentiable. ```swift public protocol DifferentiableSection : Differentiable ``` -------------------------------- ### ArraySection Equality Operator Source: https://ra1028.github.io/DifferenceKit/Structs/ArraySection.html Compares two ArraySection instances for equality. Equality is determined by comparing their models and elements. ```swift public static func == (lhs: ArraySection, rhs: ArraySection) -> Bool ``` -------------------------------- ### Elements Property Declaration Source: https://ra1028.github.io/DifferenceKit/Protocols/DifferentiableSection.html Declares the 'elements' property for DifferentiableSection, which returns the collection of elements within the section. ```swift var elements: Collection { get } ``` -------------------------------- ### Calculate Differences Between Two Sectioned Collections Source: https://ra1028.github.io/DifferenceKit/Changeset.html Use StagedChangeset to calculate differences between two sectioned collections. This is particularly useful for UI collections like UITableView or UICollectionView where simultaneous changes can cause crashes. ```swift let source = [ Section(model: "A", elements: ["😉"]), ] let target = [ Section(model: "A", elements: ["😉, 😺"]), Section(model: "B", elements: ["😪"]) ] let changeset = StagedChangeset(source: sectionedSource, target: sectionedTarget) print(changeset.isEmpty) // prints "false" ``` -------------------------------- ### StagedChangeset Replace Subrange Source: https://ra1028.github.io/DifferenceKit/Structs/StagedChangeset.html Replaces a range of Changesets within the StagedChangeset with new Changesets. Conforms to the Collection protocol. ```swift public func replaceSubrange(_ range: Range, with newElements: C) where C : Collection, C.Element == Changeset ``` -------------------------------- ### StagedChangeset Element Type Alias Source: https://ra1028.github.io/DifferenceKit/Structs/StagedChangeset.html Defines the Element type for StagedChangeset as Changeset, representing a single stage of changes. ```swift public typealias Element = Changeset ``` -------------------------------- ### Swift Struct Declaration: ArraySection Source: https://ra1028.github.io/DifferenceKit/Diffing.html A differentiable section wrapper for models and arrays of elements, allowing arrays to be identified and compared for updates. Both Model and Element must conform to Differentiable. ```swift public struct ArraySection : DifferentiableSection where Model : Differentiable, Element : Differentiable ``` -------------------------------- ### StagedChangeset Declaration Source: https://ra1028.github.io/DifferenceKit/Structs/StagedChangeset.html Declares the StagedChangeset struct with a method to replace a subrange with new elements. ```swift @inlinable public mutating func replaceSubrange(_ subrange: R, with newElements: C) where C : Collection, R : RangeExpression, C.Element == Changeset, R.Bound == Int ``` -------------------------------- ### ArraySection Difference Identifier Source: https://ra1028.github.io/DifferenceKit/Structs/ArraySection.html The differenceIdentifier property of an ArraySection, providing the model's identifier for difference calculations. ```swift @inlinable public var differenceIdentifier: Model.DifferenceIdentifier { get } ``` -------------------------------- ### replaceSubrange Source: https://ra1028.github.io/DifferenceKit/Structs/StagedChangeset.html Replaces a specified subrange of the StagedChangeset with new elements. This is a mutating operation that modifies the existing changeset. ```APIDOC ## replaceSubrange ### Description Replaces a specified subrange of the StagedChangeset with new elements. This is a mutating operation that modifies the existing changeset. ### Method `mutating func` ### Parameters #### Path Parameters - **subrange** (R): The range to replace. Must conform to `RangeExpression` with `Bound` of `Int`. - **newElements** (C): The new elements to insert. Must be a `Collection` where `Element` is `Changeset`. ### Declaration ```swift @inlinable public mutating func replaceSubrange(_ subrange: R, with newElements: C) where C : Collection, R : RangeExpression, C.Element == Changeset, R.Bound == Int ``` ``` -------------------------------- ### Associatedtype Collection Declaration Source: https://ra1028.github.io/DifferenceKit/Protocols/DifferentiableSection.html Declares the 'Collection' associated type for DifferentiableSection. This type must be a Collection and its elements must conform to the Differentiable protocol. ```swift associatedtype Collection : Collection where Self.Collection.Element : Differentiable ``` -------------------------------- ### Swift Struct Declaration: AnyDifferentiable Source: https://ra1028.github.io/DifferenceKit/Diffing.html A type-erased differentiable value that hides the specific underlying types and forwards comparisons to the underlying value. Associated type DifferenceIdentifier is erased by AnyHashable. ```swift public struct AnyDifferentiable : Differentiable ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.