Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions EditDistance.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
2B6BD4CF22B49BDC00C68FCA /* EDCollectionViewDiffableDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2B6BD4CE22B49BDC00C68FCA /* EDCollectionViewDiffableDataSource.swift */; };
2BC5BC0E1F86798300D7F4B9 /* EditDistance.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6EBF3E901E59C2FB0025443A /* EditDistance.swift */; };
2BC5BC0F1F86798500D7F4B9 /* EditDistanceContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E0301661E61689200E24C49 /* EditDistanceContainer.swift */; };
2BC5BC101F86798800D7F4B9 /* EditScriptConverter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6EBF3E461E5854C70025443A /* EditScriptConverter.swift */; };
Expand Down Expand Up @@ -67,6 +68,7 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
2B6BD4CE22B49BDC00C68FCA /* EDCollectionViewDiffableDataSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EDCollectionViewDiffableDataSource.swift; sourceTree = "<group>"; };
6E0301661E61689200E24C49 /* EditDistanceContainer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EditDistanceContainer.swift; sourceTree = "<group>"; };
6E0301681E619DB300E24C49 /* WuTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WuTests.swift; sourceTree = "<group>"; };
6E03016C1E61A8B000E24C49 /* DynamicProgrammingTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DynamicProgrammingTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -130,6 +132,7 @@
6EBF3E961E59C3BE0025443A /* EditScriptConverterProxy.swift */,
6EBF3E921E59C3640025443A /* EditScriptConverterProxy+UITableView.swift */,
6EBF3E941E59C3830025443A /* EditScriptConverterProxy+UICollectionView.swift */,
2B6BD4CE22B49BDC00C68FCA /* EDCollectionViewDiffableDataSource.swift */,
);
name = Converter;
sourceTree = "<group>";
Expand Down Expand Up @@ -420,6 +423,7 @@
6EBF3EF21E5C79330025443A /* EditDistanceAlgorithmContainer.swift in Sources */,
6E0301671E61689200E24C49 /* EditDistanceContainer.swift in Sources */,
6EBF3E4D1E58553C0025443A /* Wu.swift in Sources */,
2B6BD4CF22B49BDC00C68FCA /* EDCollectionViewDiffableDataSource.swift in Sources */,
6EBF3E471E5854C70025443A /* EditScriptConverter.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -580,6 +584,7 @@
SDKROOT = iphoneos;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
Expand Down Expand Up @@ -634,6 +639,7 @@
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
VERSIONING_SYSTEM = "apple-generic";
Expand Down
181 changes: 181 additions & 0 deletions EditDistance/EDCollectionViewDiffableDataSource.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
//
// EDCollectionViewDiffableDataSource.swift
// EditDistance
//
// Created by Kazuhiro Hayashi on 6/15/1 R.
// Copyright © 2019 Kazuhiro Hayashi. All rights reserved.
//

import UIKit

public class EDCollectionViewDiffableDataSource<SectionIdentifierType, ItemIdentifierType> : NSObject, UICollectionViewDataSource where SectionIdentifierType : Hashable, ItemIdentifierType : Hashable {

private var currentDataSource = [SectionIdentifierType: [ItemIdentifierType]]()
private let cellProvider: EDCollectionViewDiffableDataSource<SectionIdentifierType, ItemIdentifierType>.CellProvider
private let collectionView: UICollectionView

public typealias CellProvider = (UICollectionView, IndexPath, ItemIdentifierType) -> UICollectionViewCell?

public typealias SupplementaryViewProvider = (UICollectionView, String, IndexPath) -> UICollectionReusableView?

public var supplementaryViewProvider: EDCollectionViewDiffableDataSource<SectionIdentifierType, ItemIdentifierType>.SupplementaryViewProvider? {

}

public init(collectionView: UICollectionView, cellProvider: @escaping EDCollectionViewDiffableDataSource<SectionIdentifierType, ItemIdentifierType>.CellProvider) {
self.collectionView = collectionView
self.cellProvider = cellProvider
super.init()
}

public func apply(_ snapshot: EDDiffableDataSourceSnapshot<SectionIdentifierType, ItemIdentifierType>, animatingDifferences: Bool = true) {
currentDataSource
}

public func snapshot() -> EDDiffableDataSourceSnapshot<SectionIdentifierType, ItemIdentifierType> {

}

public func itemIdentifier(for indexPath: IndexPath) -> ItemIdentifierType? {

}

// TODO:- items needs search from Hashable
public func indexPath(for itemIdentifier: ItemIdentifierType) -> IndexPath? {
let sections = Array(currentDataSource.keys.enumerated())
var indexPath: IndexPath?

for section in sections {
let items = currentDataSource[section.element]
if let item = items?.enumerated().first(where: { $0.element == itemIdentifier }) {
indexPath = IndexPath(item: item.offset, section: section.offset)
break
}
}
return indexPath
}

public func numberOfSections(in collectionView: UICollectionView) -> Int {
return currentDataSource.keys.count
}

public func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
let sectionKey = Array(currentDataSource.keys)[section]
return currentDataSource[sectionKey]?.count ?? 0
}

public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let sectionKey = Array(currentDataSource.keys)[indexPath.section]
let item = currentDataSource[sectionKey][indexPath.row]
return cellProvider(collectionView, indexPath, item)
}

public func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {

}
}

public class EDDiffableDataSourceSnapshot<SectionIdentifierType, ItemIdentifierType> where SectionIdentifierType : Hashable, ItemIdentifierType : Hashable {

private var newDataSource: [SectionIdentifierType: [ItemIdentifierType]]

public init() {

}

public var numberOfItems: Int {

}

public var numberOfSections: Int {

}

public var sectionIdentifiers: [SectionIdentifierType] {

}

public var itemIdentifiers: [ItemIdentifierType] {

}

public func numberOfItems(inSection identifier: SectionIdentifierType) -> Int {

}

public func itemIdentifiers(inSection identifier: SectionIdentifierType) -> [ItemIdentifierType] {

}

public func sectionIdentifier(containingItem identifier: ItemIdentifierType) -> SectionIdentifierType? {

}

public func indexOfItem(_ identifier: ItemIdentifierType) -> Int? {

}

public func indexOfSection(_ identifier: SectionIdentifierType) -> Int? {

}

public func appendItems(_ identifiers: [ItemIdentifierType], toSection sectionIdentifier: SectionIdentifierType? = nil) {

}

public func insertItems(_ identifiers: [ItemIdentifierType], beforeItem beforeIdentifier: ItemIdentifierType) {

}

public func insertItems(_ identifiers: [ItemIdentifierType], afterItem afterIdentifier: ItemIdentifierType) {

}

public func deleteItems(_ identifiers: [ItemIdentifierType]) {

}

public func deleteAllItems() {

}

public func moveItem(_ identifier: ItemIdentifierType, beforeItem toIdentifier: ItemIdentifierType) {

}

public func moveItem(_ identifier: ItemIdentifierType, afterItem toIdentifier: ItemIdentifierType) {

}

public func reloadItems(_ identifiers: [ItemIdentifierType]) {

}

public func appendSections(_ identifiers: [SectionIdentifierType]) {

}

public func insertSections(_ identifiers: [SectionIdentifierType], beforeSection toIdentifier: SectionIdentifierType) {

}

public func insertSections(_ identifiers: [SectionIdentifierType], afterSection toIdentifier: SectionIdentifierType) {

}

public func deleteSections(_ identifiers: [SectionIdentifierType]) {

}

public func moveSection(_ identifier: SectionIdentifierType, beforeSection toIdentifier: SectionIdentifierType) {

}

public func moveSection(_ identifier: SectionIdentifierType, afterSection toIdentifier: SectionIdentifierType) {

}

public func reloadSections(_ identifiers: [SectionIdentifierType]) {

}
}
2 changes: 2 additions & 0 deletions iOS Example/iOS Example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@
SDKROOT = iphoneos;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
Expand Down Expand Up @@ -448,6 +449,7 @@
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
};
Expand Down