diff --git a/EditDistance.xcodeproj/project.pbxproj b/EditDistance.xcodeproj/project.pbxproj index c325d9d..5dbc4cd 100644 --- a/EditDistance.xcodeproj/project.pbxproj +++ b/EditDistance.xcodeproj/project.pbxproj @@ -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 */; }; @@ -67,6 +68,7 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 2B6BD4CE22B49BDC00C68FCA /* EDCollectionViewDiffableDataSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EDCollectionViewDiffableDataSource.swift; sourceTree = ""; }; 6E0301661E61689200E24C49 /* EditDistanceContainer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EditDistanceContainer.swift; sourceTree = ""; }; 6E0301681E619DB300E24C49 /* WuTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WuTests.swift; sourceTree = ""; }; 6E03016C1E61A8B000E24C49 /* DynamicProgrammingTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DynamicProgrammingTests.swift; sourceTree = ""; }; @@ -130,6 +132,7 @@ 6EBF3E961E59C3BE0025443A /* EditScriptConverterProxy.swift */, 6EBF3E921E59C3640025443A /* EditScriptConverterProxy+UITableView.swift */, 6EBF3E941E59C3830025443A /* EditScriptConverterProxy+UICollectionView.swift */, + 2B6BD4CE22B49BDC00C68FCA /* EDCollectionViewDiffableDataSource.swift */, ); name = Converter; sourceTree = ""; @@ -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; @@ -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 = ""; @@ -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"; diff --git a/EditDistance/EDCollectionViewDiffableDataSource.swift b/EditDistance/EDCollectionViewDiffableDataSource.swift new file mode 100644 index 0000000..bc64324 --- /dev/null +++ b/EditDistance/EDCollectionViewDiffableDataSource.swift @@ -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 : NSObject, UICollectionViewDataSource where SectionIdentifierType : Hashable, ItemIdentifierType : Hashable { + + private var currentDataSource = [SectionIdentifierType: [ItemIdentifierType]]() + private let cellProvider: EDCollectionViewDiffableDataSource.CellProvider + private let collectionView: UICollectionView + + public typealias CellProvider = (UICollectionView, IndexPath, ItemIdentifierType) -> UICollectionViewCell? + + public typealias SupplementaryViewProvider = (UICollectionView, String, IndexPath) -> UICollectionReusableView? + + public var supplementaryViewProvider: EDCollectionViewDiffableDataSource.SupplementaryViewProvider? { + + } + + public init(collectionView: UICollectionView, cellProvider: @escaping EDCollectionViewDiffableDataSource.CellProvider) { + self.collectionView = collectionView + self.cellProvider = cellProvider + super.init() + } + + public func apply(_ snapshot: EDDiffableDataSourceSnapshot, animatingDifferences: Bool = true) { + currentDataSource + } + + public func snapshot() -> EDDiffableDataSourceSnapshot { + + } + + 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 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]) { + + } +} diff --git a/iOS Example/iOS Example.xcodeproj/project.pbxproj b/iOS Example/iOS Example.xcodeproj/project.pbxproj index a7f1169..8f611a1 100644 --- a/iOS Example/iOS Example.xcodeproj/project.pbxproj +++ b/iOS Example/iOS Example.xcodeproj/project.pbxproj @@ -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; @@ -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; };